Declare Variables in Array

M

Mike H.

If I wish to dimension this array: DataArray(300,4) and I know this:
1st element of second dimension will be long
2nd element of second dimension will be string
3rd element of second dimension will be integer
4th element of second dimension will be variant (maybe string, maybe long,
etc).
All elements of first dimension would be variant

The way I currently dim this is:
Dim DataArray(300,4) as variant
Can I precisely dimension this array? How? Thanks.
 
B

Bob Phillips

Public Type MyUDT
MyLong As Long
MyString As String
MyInteger As Integer
MyVariant As Variant
End Type

Sub Test()
Dim DataArray(1 To 300) As MyUDT
Dim tmp As MyUDT

tmp.MyLong = 33000
tmp.MyString = "Bob"
tmp.MyInteger = 17
tmp.MyVariant = Array(1, 2, 3)
DataArray(1) = tmp

End Sub
 
B

Bob Phillips

or simply

Public Type MyUDT
MyLong As Long
MyString As String
MyInteger As Integer
MyVariant As Variant
End Type

Sub Test()
Dim DataArray(1 To 300) As MyUDT

DataArray(1).MyLong = 33000
DataArray(1).MyString = "Bob"
DataArray(1).MyInteger = 17
DataArray(1).MyVariant = Array(1, 2, 3)

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top