Article ID: 186423
Article Last Modified on 7/13/2004
StringArray = IntegerArray
Option Explicit
Public Function ArrayFromClass() As String()
Dim aStr(1 To 10) As String
Dim i As Integer
For i = 1 To 10
aStr(i) = "Class array element " & Str(i)
Next i
ArrayFromClass = aStr()
End Function
Option Explicit
Private aiLeftSide() As Integer
Private asLeftSide() As String
Private aiRightSide(1 To 10) As Integer
Private asRightSide(1 To 10) As String
Private obj As Object
Private Sub Command1_Click()
Dim i As Integer
aiLeftSide = aiRightSide
'try assigning arrays of different types by changing the next line
' to aiLeftSide = asRightSide
asLeftSide = asRightSide
For i = 1 To UBound(aiLeftSide)
Debug.Print aiLeftSide(i)
Next i
For i = 1 To UBound(asLeftSide)
Debug.Print asLeftSide(i)
Next i
End Sub
Private Sub Command2_Click()
Dim i As Integer
Dim aInt() As Integer
Dim astr() As String
aInt = ReturnIntArray
'try assigning arrays of different types by changing the next line
' to aInt = ReturnStringArray
astr = ReturnStringArray
For i = 1 To UBound(aInt)
Debug.Print aInt(i)
Next i
For i = 1 To UBound(astr)
Debug.Print astr(i)
Next i
End Sub
Private Sub Command3_Click()
'To see what kind of error you get when a late-bound object
'returns an array that is of a different type than the receiving
'array, change the next line of code to be Dim astr() as Integer
Dim astr() As String
Dim i As Integer
astr = obj.ArrayFromClass
For i = 1 To UBound(astr)
Debug.Print astr(i)
Next i
End Sub
Private Sub Form_Load()
Dim i As Integer
Command1.Caption = "Assign Array"
Command2.Caption = "Call Function that returns Array"
Command3.Caption = "Call Object method that returns Array"
For i = 1 To 10
aiRightSide(i) = i
asRightSide(i) = "This is element " & Str(i)
Next i
Set obj = New Class1
End Sub
Private Function ReturnStringArray() As String()
Dim aString(1 To 10) As String
Dim i As Integer
For i = 1 To UBound(aString)
aString(i) = "Element " & Str(i)
Next i
ReturnStringArray = aString()
End Sub
Private Function ReturnIntArray() As Integer()
Dim aInt(1 To 10) As Integer
Dim i As Integer
For i = 1 To 10 'UBound(aInt)
aInt(i) = i
Next i
ReturnIntArray = aInt()
End Sub
Additional query words: kbDSupport kbDSD kbVBA kbVB600 kbDSupport
Keywords: kbhowto KB186423