Thursday 15 November 2007

VB and VBScript passing array to a function

Private Sub PassArray()
Dim myArray() 'Declare a Static Integer Array of 4 elements
Dim arrayIndex

arrayIndex = 0
ReDim Preserve myArray(arrayIndex)
myArray(0) = "one"

arrayIndex=arrayIndex+1
ReDim Preserve myArray(arrayIndex)
myArray(1) = "two"

arrayIndex=arrayIndex+1
ReDim Preserve myArray(arrayIndex)
myArray(2) = "three"

arrayIndex=arrayIndex+1
ReDim Preserve myArray(arrayIndex)
myArray(3) = "four"

Call AcceptArray(myArray) 'Call the procedure and pass the Array
End Sub

Private Sub AcceptArray(outArray())
dim iCount
For iCount=0 to ubound(outArray)
WScript.echo outArray(iCount)
Next
End Sub

No comments: