Stupid Array Question

  • Thread starter Thread starter Crystal
  • Start date Start date
C

Crystal

I should know this, but I don't think I do.

I have two data types, Integer and String. I need to make
a two dimensional array. I don't think I can have two
different data types in an array like that? Can I?

If not, how would I get around this?

Any help would be greatly appreciated,
Crystal
 
Hello Crystal,

Yes you can. Declare your array as a variant.

example:

Declare X(1,1) AS Variant


Hope this helps,
Jorge
 
Crystal said:
I should know this, but I don't think I do.

I have two data types, Integer and String. I need to make
a two dimensional array. I don't think I can have two
different data types in an array like that? Can I?

If not, how would I get around this?

You can if the array is type Variant.

Dim varArray(100, 2) As Variant
varArray(x, 1) = 123
varArray(x, 2) = "string"

Another way that might be more intuitive is to use two one
dimensional arrays:

Dim lngNum(100) As Long
Dim strText(100) As String
lngNum(x) = 123
strText(x) = "string"
 
Depending on how 'neat' you want to be, you could define a Type:

This has the advantage of making the logical associations of the respective
data elements a lot clearer, centralises array limits, amenable to ReDim etc
etc

Type typ_Holiday
Location As String
Cost As Integer
End Type

Sub Use_UDT_Array
Dim Holidays(60) As typ_Holiday, i As Integer
i = 15
Holidays(i).Location = "Tangiers"
Holidays(i).Cost = 1300
End Sub

CD
 
Back
Top