本文介绍了循环通过vba中的类的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我创建了这个课程, 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> '公共属性获取项(我作为整数)作为变量 选择案例ndx 案例1:项目= Me.x 案例2:项目= Me.y 案例3:项目= Me.z 结束选择 结束属性 ' Dim c as Collection Dim s as String 对于i = 1到3 如果i set c = inter.Item(i)'通过集合 else s = inter.Item(i) end if next i 这样的东西可能是最简单的方法,我没有测试,但希望至少让你开始 I have created this class,Interval.clspublic x as new collectionpublic y as new collectionpublic z as stringI wish to loop through the properties because I want the user to choose input x,y,z in the form so at my subsub test()dim inter as new Intervalsinter.x.add "a"inter.x.add "a"inter.x.add "b"inter.x.add "b"inter.x.add "b"userString1 = xuserString2 = 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 propertiesfor 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) thenend ifnext iend subI know i can maybe make a tweek in the class to make it iterable, i don't know how to do itany help is appreciated 解决方案 'in classPublic 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 SelectEnd Property'in subDim c as CollectionDim s as StringFor i = 1 to 3 if i < 3 then set c = inter.Item(i) 'iterate through collection else s = inter.Item(i) end ifnext isomething like this is probably the easiest way to go, i didnt test it but hopefully it at least gets you started 这篇关于循环通过vba中的类的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-20 20:58