循环通过vba中的类的属性 [英] Loop through properties of a class in vba
问题描述
我创建了这个课程,
Interval.cls
public x作为新集合
public y作为新集合
public z as string
我希望循环访问属性,因为我希望用户选择输入x,y,z,所以在我的sub
sub test()
dim inter作为新间隔
inter.x.adda
inter.x.adda
inter.x.addb
inter.x.addb
inter.x.addb
userString1 = x
userString2 = a
'我想使其动态化,以便无论用户想要什么,我都可以提供结果。
'我只是想让每个我在$
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ b
'所以我希望我在这个循环中是我的属性x,y,z,所以我可以if语句
if(i = userString1)then
end if
next i
end sub
我知道我可以在课堂上做一个tweek,使其迭代,我不知道如何做到这一点
任何帮助都赞赏
<$ p $类
中的p> '公共属性获取项(我作为整数)作为变量
选择案例ndx
案例1:项目= Me.x
案例2:项目= Me.y
案例3:项目= Me.z
结束选择
结束属性
'
Dim c as Collection
Dim s as String
对于i = 1到3
如果i < 3然后
set c = inter.Item(i)
'通过集合
else
s = inter.Item(i)
end if
next i
这样的东西可能是最简单的方法,我没有测试,但希望至少让你开始
I have created this class,
Interval.cls
public x as new collection
public y as new collection
public z as string
I wish to loop through the properties because I want the user to choose input x,y,z in the form so at my sub
sub test()
dim inter as new Intervals
inter.x.add "a"
inter.x.add "a"
inter.x.add "b"
inter.x.add "b"
inter.x.add "b"
userString1 = x
userString2 = a
' I want to make it dynamic so that whatever the user wants i can provide the results. 'i just want to make it possible to compare the userString to my properties
for each i in inter
'so i wish for i in this loop to be my properties x,y,z so i can make the if statement if ( i = userString1) then
end if
next i
end sub
I know i can maybe make a tweek in the class to make it iterable, i don't know how to do it
any help is appreciated
'in class
Public Property Get Item(i As Integer) As Variant
Select Case ndx
Case 1: Item = Me.x
Case 2: Item = Me.y
Case 3: Item = Me.z
End Select
End Property
'in sub
Dim c as Collection
Dim s as String
For i = 1 to 3
if i < 3 then
set c = inter.Item(i)
'iterate through collection
else
s = inter.Item(i)
end if
next i
something like this is probably the easiest way to go, i didnt test it but hopefully it at least gets you started
这篇关于循环通过vba中的类的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!