3
性能我有以下语法如下的一个类似13点的属性:阵列中VBA
Public Property Get Town() As String
Town = txtTown.Text
End Property
我想能够使用一个循环,并遍历这些属性的集合而不是引用的每一个的13个属性。我将如何去创建这些预先存在的属性的数组。我非常希望他们保留他们有意义的名字。
编辑:
aSet IDCell = customerDBSheet.Range("CustomerDBEntryPoint").Offset(ID() - 1)
Dim properties()
properties = Array("ID()", "FirstName()", "LastName()", "Address 1()", "Address 2()", "Town()", "Postcode()", "Phone()", "Email()", "Sex()", "Username()", "PasswordHash()")
For i = 0 To 11
IDCell.Offset(1, i).Value = CStr(CallByName(frmCustomerEntry, properties(i), VbLet, ""))
Next i
我上线的错误前年:IDCell.Offset(1, i).Value = CStr(CallByName(frmCustomerEntry, properties(i), VbLet, ""))
终极密码:
Dim properties()
properties = Array("ID", "FirstName", "LastName", "Address1", "Address2", "Town", "Postcode", "Phone", "Email", "Sex", "Username", "PasswordHash")
For i = 0 To 11
IDCell.Offset(1, i).Value = CStr(CallByName(frmCustomerEntry, properties(i), VbMethod))
Next i
到底使用的代码所示,上面特别使用Radek的答案编辑的CallByName函数作为t他的财产被转换为一个功能。此外,For循环需要使用基于0的索引。此外,当第四个可选参数是空字符串文字时,会引发异常。
谢谢出色答卷(更得心应手一点: – Kian 2012-02-19 22:48:42
什么的MyObject1参考? – Kian 2012-02-20 00:20:02
MyObject1是实现13个属性的类的实例 – Radek 2012-02-20 08:43:42