My problem can be illustrated in the following example code, which sets up a data array of friends, each of which can have several phone numbers:
Class clsPhoneNo
Dim strType
Dim strNumber
End Class
Class clsPerson
Dim strName
Dim aclsPhoneNo()
End Class
Dim clsFriends()
ReDim clsFriends(3)
Set clsFriend(0) = New Person
clsFriend(0).strName = "Fred"
Set clsFriends(0).aclsPhoneNo(0) = New clsPhoneNo
ReDim clsFriend(0).aclsPhoneNo(2)
Set clsFriend(0).aclsPhoneNo(0).strType = "Home"
Set clsFriend(0).aclsPhoneNo(0) = "01234567890"
Set clsFriend(0).aclsPhoneNo(1).strType = "Work"
Set clsFriend(0).aclsPhoneNo(1) = "09876543210"
However, VBScript says
Microsoft VBScript compilation error: Expected end of statement
Before the . on the second ReDim statement
I need to have the aclsPhoneNo element variable length as my code isn’t really an address book, but this is a simple example demonstrating the issue.
Any ideas?
Arrays are the wrong data structure to solve this problem. They are the weapon of choice in other languages, they are not in VBScript, for they are notoriously inflexible.
Consider using Dictionaries instead. And drop the Hungarian.
Note that I made use of a few VB features here
PublicandPrivateclass variablesInitiateand aTerminateevent that you can react toWithblock can save you a temporary variable as well.