I am new to VB in general. I am going through some old VB code and I see statements like –
Addr.AddrType(CStr(0)).A_Type = " "
Why does the integer 0 have to be converted to a string?
Note that Addr is defined as
Public Addr As clsAddressDetail
AddrType is defined as a collection
Public AddrType As New Collection
The
Collectionclass being used here has what is effectively an overloaded indexer. My emphases:So, if you ask for
AddrType(0), you are asking for the zeroth member of the collection, which for this 1-based collection is an error. But if you ask forAddrType("0"), you are asking for that member which was added with Key"0". Any string can be used as a key – it’s just that the particular string used here is the string representation of a number.Incidentally, stylistically I would say writing
CStr(0)rather than"0"isn’t particularly nice…