Please help, I am working on an Active-x project involving Arrays with up
to
20 elements populated in a class module. In order to keep programming and
debugging simple, Instead of refering to each element with numbers, would it
be correct to refer to each element with constants as per the example shown
bellow.
Option Explicit
Dim AddrArray(1 To 20, 1 To 3)
Dim Address As clsMyClass
Dim MyStr As String
Dim intX As Integer
Const First = 1
Const Last = 2
Const Phone = 3
Sub Main()
Set Address = New clsMyClass
Address.AddrBoo k First, Last, Phone, AddrArray()
For intX = 1 To 4
MsgBox AddrArray(intX, First) & vbCr & AddrArray(intX, Last) & vbCr &
AddrArray(intX, Phone)
Next intX
End Sub
'' with this in a class module called clsMyClass
Public Function AddrBook(First, Last, Phone, AddrArray())
AddrArray(1, First) = "Joe"
AddrArray(1, Last) = "Bloggs"
AddrArray(1, Phone) = "5551234"
AddrArray(2, First) = "Sarah"
AddrArray(2, Last) = "Bloggs"
AddrArray(2, Phone) = "5554321"
AddrArray(3, First) = "John"
AddrArray(3, Last) = "Doh"
AddrArray(3, Phone) = "5551111"
AddrArray(4, First) = "Jane"
AddrArray(4, Last) = "Doh"
AddrArray(4, Phone) = "5554444"
End Function
'' Please note: hard-coded for simplicity
If there is a simpler way of doing this, I would greatly appreciate any
help,
Thanks in advance
Paul
to
20 elements populated in a class module. In order to keep programming and
debugging simple, Instead of refering to each element with numbers, would it
be correct to refer to each element with constants as per the example shown
bellow.
Option Explicit
Dim AddrArray(1 To 20, 1 To 3)
Dim Address As clsMyClass
Dim MyStr As String
Dim intX As Integer
Const First = 1
Const Last = 2
Const Phone = 3
Sub Main()
Set Address = New clsMyClass
Address.AddrBoo k First, Last, Phone, AddrArray()
For intX = 1 To 4
MsgBox AddrArray(intX, First) & vbCr & AddrArray(intX, Last) & vbCr &
AddrArray(intX, Phone)
Next intX
End Sub
'' with this in a class module called clsMyClass
Public Function AddrBook(First, Last, Phone, AddrArray())
AddrArray(1, First) = "Joe"
AddrArray(1, Last) = "Bloggs"
AddrArray(1, Phone) = "5551234"
AddrArray(2, First) = "Sarah"
AddrArray(2, Last) = "Bloggs"
AddrArray(2, Phone) = "5554321"
AddrArray(3, First) = "John"
AddrArray(3, Last) = "Doh"
AddrArray(3, Phone) = "5551111"
AddrArray(4, First) = "Jane"
AddrArray(4, Last) = "Doh"
AddrArray(4, Phone) = "5554444"
End Function
'' Please note: hard-coded for simplicity
If there is a simpler way of doing this, I would greatly appreciate any
help,
Thanks in advance
Paul
Comment