VBA:通过子程序调用参数转发类型
我第一次进入这里 编写VBA,相当陌生 ================================================================= 目标:将坐标输入到对象/类中 。。。意思是“等等” 现在的解决方案是:使用数组,例如 ================================================================= 类别1:VBA:通过子程序调用参数转发类型,vba,types,Vba,Types,我第一次进入这里 编写VBA,相当陌生 ================================================================= 目标:将坐标输入到对象/类中 。。。意思是“等等” 现在的解决方案是:使用数组,例如 ================================================================= 类别1: sub start() Dim c2 as new Class2 Dim point
sub start()
Dim c2 as new Class2
Dim points() as Double
Redim points(7)
point(0) = ...
...
point(7) = ...
cs.draw points
end sub
类别2:
public Sub draw(points() as double)
...
end sub
public Sub draw(p as Properties) '<---- Class 2 also need access to properties?
...
doCoolStuff(p.length)
doOtherCoolStuff(p.keygripp, p.diameter)
...
end sub
=================================================================
问题是:硬跟踪开关阵列插槽代表一个特定的兴趣值
我想做的是:
第1类:
Type Properties
length As Double
keygripp As Double
diameter As Double
tapdiameter As Double
steerlength As Double
distance As Double
plateau As Double
End Type
sub start()
Dim c2 as new Class2
Dim points as Properties
point.length = ...
...
point.plateau = ...
cs.draw points
end sub
类别2:
public Sub draw(points() as double)
...
end sub
public Sub draw(p as Properties) '<---- Class 2 also need access to properties?
...
doCoolStuff(p.length)
doOtherCoolStuff(p.keygripp, p.diameter)
...
end sub
public Sub draw(p as Properties)”据我所知,您可以创建例如Point
类,并在集合中使用它,然后将此集合的实例传递给draw
方法。嗯
注意:名称点
与问题中的名称属性
相对应
点类模块
处理器类模块
标准模块
如果希望保留用户定义的类型,请在标准模块中声明该类型,然后将其与数组一起使用(UDT不能与VBA.Collection
一起使用)
标准模块
类处理器
据我所知,您可以创建例如Point
类,并在集合中使用它,然后将此集合的实例传递给Draw
方法。嗯
注意:名称点
与问题中的名称属性
相对应
点类模块
处理器类模块
标准模块
如果希望保留用户定义的类型,请在标准模块中声明该类型,然后将其与数组一起使用(UDT不能与VBA.Collection
一起使用)
标准模块
类处理器
NET、VBA和VBScript都是不同的。请删除不相关的标签。也请查看并获取。不确定您希望我编辑什么,仅“VBA”和“类型”作为标记。它看起来已经由Lankymart.VB.NET自动生成,VBA和VBScript都是不同的。请删除不相关的标签。请查看并获取。不确定您希望我编辑什么,仅“VBA”和“类型”作为标记。它看起来已经由Lankymart自动生成。
Sub Start()
Dim pt As Point
Set pt = New Point
pt.Length = 123
' pt.plateau = ...
Dim points As VBA.Collection
Set points = New VBA.Collection
points.Add pt
Dim proc As Processor
Set proc = New Processor
proc.Draw points
End Sub
Type PointType
length As Double
keygripp As Double
diameter As Double
tapdiameter As Double
steerlength As Double
distance As Double
plateau As Double
End Type
Sub start()
Dim pt As PointType
pt.length = 555
Dim pt2 As PointType
pt2.length = 666
Dim pts(1 To 2) As PointType
pts(1) = pt
pts(2) = pt2
Dim proc As Processor
Set proc = New Processor
proc.Draw pts
End Sub
Public Sub Draw(pts() As PointType)
' use for-next isnatead of for-each-next here