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
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
Private Sub Command1_Click()
Dim i As Integer
aiLeftSide = aiRightSide
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
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()
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
aInt(i) = i
Next i
ReturnIntArray = aInt()
End Sub
Sunday, June 17, 2012
Memperoleh Array Dari Prosedur Fungsi
Labels:
Array