我刚刚试图做一个班的类。我在网站上逛过,看过几个例子,但也许因为1:43我很难理解它们。一类的课
我成功地使用一个类来自动化一个巨大的数据录入项目。我创建了一个名为catDist的类,它是一家公司可以生产或销售的农产品类型的分类分布。
catDist包含六个属性: 私人selfWorth作为字符串 私人Q1为双 私人Q2为双 私人Q3为双 私人Q4为双 私人激活为布尔
他们都有标准得到和让代码。
有48种可能的类别。我有一个模块可以为selfWorth(例如“Cottonseed”或“maize”等)创建48个不同值的实例,并将Q1至Q4设置为0。该模块最初与一个用户窗体一起工作,我可以输入值并按回车键。如果它看到我在一个特定的文本框中输入了一个值(是的,那里有48X4个文本框),它将被设置为true并将相关的Q值更改为我输入的值。
我现在想做什么。
这是一个巨大的成功。现在我想要做的是创建一个名为“分销商”的类。每个分销商类将有4个集合拥有catDist对象。我可以创建分销商类。我可以创建catDist类。但是对于上帝的爱,我无法想出将相应分销商的CatDist属性设置为我在Set方法中使用的catDist值的方法。
Sub testRegist()
Dim registrant As testRegistrant
Set registrant = New testRegistrant
registrant.registNum = "Z000123"
'MsgBox (registrant.registNum)
Dim cowMilk As testcatDist
Set cowMilk = New testcatDist
cowMilk.selfWorth = "Cow Milk"
cowMilk.distribution = 4.6
registrant.testCat = cowMilk
Debug.Print registrant.testCat.selfWorth
End Sub
catDist类
Private pselfWorth As String
Private pdistribution As Double
Public Property Get selfWorth() As String
selfWorth = pselfWorth
End Property
Public Property Let selfWorth(name As String)
pselfWorth = name
End Property
Public Property Get distribution() As Double
distribution = pdistribution
End Property
Public Property Let distribution(dist As Double)
pdistribution = dist
End Property
注册人a.k.a经销商类
Private pRegistNum As String
Private pCatDist As testcatDist
Public Property Get registNum() As String
registNum = pRegistNum
End Property
Public Property Let registNum(registration As String)
pRegistNum = registration
End Property
Public Property Get testCat() As testcatDist
testCat = pCatDist
End Property
Public Property Let testCat(cat As testcatDist)
Set pCatDist = New testcatDist
pCatDist = cat
End Property
请显示一些代码:) – 2014-10-12 05:56:48
哈哈我试图避免这一点。我会把我用来试验这个概念的一个简化版本。 – 2014-10-12 05:57:25
如果您阅读了此处发布的最佳做法,请参阅您希望发布一个简短的自描述正确的代码示例。原因是,如果我们能够理解具体问题,帮助你更容易 – 2014-10-12 05:59:23