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