Created
April 4, 2011 16:00
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' 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 |
Me too - I switched to JScript which is so much more sane and familiar
and equally supported under the Windows Script Host. I appreciate your
taking the time to consider this though.
Thanks,
- Sean
…On Thu, Jul 7, 2011 at 11:50 AM, sholsinger ***@***.*** wrote:
Keenskelly I think I might have figured out what your problem was. I tried to use the ArrayAppend() method to append an array to another array and that doesn't work. It will work on all primitives though -- and might work for Objects. The logic to re-dim an array into a multi-dimensional array is just much more than I'm willing to spend time writing right now. I hate the way VBScript handles arrays.
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/901874
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Keenskelly I think I might have figured out what your problem was. I tried to use the ArrayAppend() method to append an array to another array and that doesn't work. It will work on all primitives though -- and might work for Objects. The logic to re-dim an array into a multi-dimensional array is just much more than I'm willing to spend time writing right now. I hate the way VBScript handles arrays.