Skip to content

Instantly share code, notes, and snippets.

@sholsinger
Created April 4, 2011 16:00
Show Gist options
  • Save sholsinger/901874 to your computer and use it in GitHub Desktop.
Save sholsinger/901874 to your computer and use it in GitHub Desktop.
VBScript Tools for measuring the length of an array and appending values to a Dynamic array
' appends the second argument to the first if the first is an array.
' MUST be a dynamic array! Returns new array.
' Usage:
' Dim myArray()
' myArray = ArrayAppend(myArray, "foo")
Function ArrayAppend( a, o )
On Error Resume Next
Err.Clear()
dim tn, i
i = 0
tn = TypeName(o)
If isArray(a) Then
i = UBound(a)
If Err.number <> 0 Then
Err.Clear() ' We know this causes an error every time.
Else
i = i+1
End If
ReDim Preserve a(i)
If tn <> "Object" Then
a(i) = o
Else
Set a(i) = o
End If
End If
ArrayAppend = a
End Function
' gets the length of an array.
Function ArrayLength( a )
On Error Resume Next
dim i: i = 0
i = UBound(a) + 1
ArrayLength = i
Err.Clear()
End Function
@keenskelly
Copy link

keenskelly commented Jul 7, 2011 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment