How to Check if It is a Reserved Keyword in VBScript?
Althought not all the following keywords are used in VBScript, but they are reserved. For example, the 'AS' keyword is not used in VBScript (but they are used in Visual Basic where a variable is declared AS a type). In VBScript, all variables are variant types meaning they can be integer at a time and then later used as a string depending on the programming context.
If you have the following in VBScript:
Dim As
The Interpreter (cscript.exe or wscript.exe) will report error because AS is a reserved keyword and cannot be declared as a variable. Please note that this Online VBScript Obfuscator preserves all the keywords in the VBScript source code.
Microsoft VBScript compilation error: Expected identifierThere are 79 reserved keywords in VBScript (the following sorted alphabetically):
And As Boolean ByRef Byte ByVal Call Case Class Const
Currency Debug Dim Do Double Each Else ElseIf Empty End
EndIf Enum Eqv Event Exit False For Function Get GoTo
If Imp Implements In Integer Is Let Like Long Loop
LSet Me Mod New Next Not Nothing Null On Option
Optional Or ParamArray Preserve Private Public RaiseEvent ReDim Rem Resume
RSet Select Set Shared Single Static Stop Sub Then To
True Type TypeOf Until Variant Wend While With Xor
The CheckReserved Function in VBScript
We can use the Execute function to execute the statement, if it is not a keyword, then no errors will be generated, otherwise, it will throw out errors. However, we have to disable the error thrown in the function by telling VBScript On Error Resume Next, after we check the result, we enable the error reporting by On Error Goto 0.
Function IsReserved(keyword)
On Error Resume Next
Execute "Dim " & keyword
IsReserved = Err.Number <> 0
On Error GoTo 0
End Function
Alternatively, you can just check the keyword against the list. Use the following function (Select-Case Syntax) to check if a keyword (case insensitive) is a reserved keyword in VBScript.
Function IsReserved(keyword)
IsReserved = False
Select Case LCase(keyword)
Case "and": IsReserved = True
Case "as": IsReserved = True
Case "boolean": IsReserved = True
Case "byref": IsReserved = True
Case "byte": IsReserved = True
Case "byval": IsReserved = True
Case "call": IsReserved = True
Case "case": IsReserved = True
Case "class": IsReserved = True
Case "const": IsReserved = True
Case "currency": IsReserved = True
Case "debug": IsReserved = True
Case "dim": IsReserved = True
Case "do": IsReserved = True
Case "double": IsReserved = True
Case "each": IsReserved = True
Case "else": IsReserved = True
Case "elseif": IsReserved = True
Case "empty": IsReserved = True
Case "end": IsReserved = True
Case "endif": IsReserved = True
Case "enum": IsReserved = True
Case "eqv": IsReserved = True
Case "event": IsReserved = True
Case "exit": IsReserved = True
Case "false": IsReserved = True
Case "for": IsReserved = True
Case "function": IsReserved = True
Case "get": IsReserved = True
Case "goto": IsReserved = True
Case "if": IsReserved = True
Case "imp": IsReserved = True
Case "implements": IsReserved = True
Case "in": IsReserved = True
Case "integer": IsReserved = True
Case "is": IsReserved = True
Case "let": IsReserved = True
Case "like": IsReserved = True
Case "long": IsReserved = True
Case "loop": IsReserved = True
Case "lset": IsReserved = True
Case "me": IsReserved = True
Case "mod": IsReserved = True
Case "new": IsReserved = True
Case "next": IsReserved = True
Case "not": IsReserved = True
Case "nothing": IsReserved = True
Case "null": IsReserved = True
Case "on": IsReserved = True
Case "option": IsReserved = True
Case "optional": IsReserved = True
Case "or": IsReserved = True
Case "paramarray": IsReserved = True
Case "preserve": IsReserved = True
Case "private": IsReserved = True
Case "public": IsReserved = True
Case "raiseevent": IsReserved = True
Case "redim": IsReserved = True
Case "rem": IsReserved = True
Case "resume": IsReserved = True
Case "rset": IsReserved = True
Case "select": IsReserved = True
Case "set": IsReserved = True
Case "shared": IsReserved = True
Case "single": IsReserved = True
Case "static": IsReserved = True
Case "stop": IsReserved = True
Case "sub": IsReserved = True
Case "then": IsReserved = True
Case "to": IsReserved = True
Case "true": IsReserved = True
Case "type": IsReserved = True
Case "typeof": IsReserved = True
Case "until": IsReserved = True
Case "variant": IsReserved = True
Case "wend": IsReserved = True
Case "while": IsReserved = True
Case "with": IsReserved = True
Case "xor": IsReserved = True
End Select
End Function
Contact Me
via Web Email.Donation helps
Donation helps the cost of the domain/server, and is very much appreciated.
Why Donate?
Check This page for a few reasons. :)Page Edited on Irregular Basis: 25/Apr/2019 12:35:44
View in AMP (Accelerated Mobile Pages) Version