VBScript Snippets
Handy VBScript snippets to copy/paste.
General Use
URLEncode
Apparently there is no URLEncode in the VBScript default library. Go figure. So this escape unsafe values for inclusion in a URL or POST data. This only handles the most common cases though.
Function URLEncode(s)
s = Replace(s, "%", "%25")
s = Replace(s, "$", "%24")
s = Replace(s, "&", "%26")
s = Replace(s, "+", "%2B")
s = Replace(s, ",", "%2C")
s = Replace(s, "/", "%2F")
s = Replace(s, ":", "%3A")
s = Replace(s, ";", "%3B")
s = Replace(s, "=", "%3D")
s = Replace(s, "?", "%3F")
s = Replace(s, "@", "%40")
s = Replace(s, " ", "%20")
URLEncode = s
End Function
ArrayPush
Good old array push – will push a single value onto an array.
Hard to believe the things we take for granted in more modern languages and take a good 10 lines in VBScript.
Sub ArrayPush(ByRef a, v)
If IsEmpty(a) Then
Redim a(0)
Else
Redim Preserve a(UBound(a) + 1)
End If
If IsObject(v) Then
Set a(UBound(a)) = v
Else
a(UBound(a)) = v
End If
End Sub





