๐๏ธ ASP โ VB Keywords โ Essential VBScript Reserved Words for Classic ASP
๐งฒ Introduction โ What Are VB Keywords in Classic ASP?
VBScript keywords (also called reserved words) are predefined words in the VBScript language used by Classic ASP. These words are part of the language syntax and cannot be used as variable names or identifiers. Understanding these keywords is essential for writing valid and functional ASP pages.
๐ฏ In this guide, youโll learn:
- The list of built-in VBScript keywords used in Classic ASP
- Their purposes and typical use cases
- Code examples for each major keyword group
- Common mistakes and best practices
๐๏ธ Categories of VBScript Keywords
VBScript keywords in Classic ASP can be grouped as follows:
Category | Examples |
---|---|
Control Flow | If , Else , Select , Case , For , Next , While , Do , Loop , Exit |
Declarations | Dim , Const , Function , Sub , Call , Set |
Operators | And , Or , Not , Mod , Is , Like |
Error Handling | On Error Resume Next , Err , IsObject |
Type & Value | Nothing , True , False , Empty , Null |
Miscellaneous | Option Explicit , ByVal , ByRef , Class , New |
๐ Control Flow Keywords
These control logic and decision-making in ASP.
<%
Dim age
age = 22
If age >= 18 Then
Response.Write "Adult"
Else
Response.Write "Minor"
End If
%>
Keyword | Purpose |
---|---|
If | Starts a conditional block |
Then | Executes block if condition true |
Else | Defines alternate logic |
Select Case | Multibranch condition |
For , Next | Looping structure |
Do , While , Loop | Conditional loops |
๐งฑ Declaration Keywords
Used to declare variables, constants, functions, and procedures.
<%
Dim name
Const MAX = 10
Function Add(x, y)
Add = x + y
End Function
%>
Keyword | Purpose |
---|---|
Dim | Declare variables |
Const | Define constants |
Function | Define a function that returns value |
Sub | Define a procedure |
Set | Assign an object reference |
Call | Call a subroutine (optional) |
โ๏ธ Operators & Logical Keywords
<%
Dim a, b
a = 10
b = 20
If a < b And b < 100 Then
Response.Write "Valid range"
End If
%>
Keyword | Purpose |
---|---|
And | Logical AND |
Or | Logical OR |
Not | Logical negation |
Mod | Modulus operator (remainder) |
Is | Compare objects |
Like | Pattern matching in strings |
๐ Error Handling Keywords
<%
On Error Resume Next
Dim result
result = 10 / 0 ' No error displayed
If Err.Number <> 0 Then
Response.Write "An error occurred: " & Err.Description
End If
%>
Keyword | Purpose |
---|---|
On Error Resume Next | Suppresses runtime error messages |
Err | Error object for handling exceptions |
IsObject | Checks if a variable is an object |
๐ก Type & Value Constants
<%
Dim status
status = Null
If IsNull(status) Then
Response.Write "Status is unknown"
End If
%>
Keyword | Purpose |
---|---|
Null | Represents no valid data |
Empty | Uninitialized variable |
Nothing | No object is assigned |
True | Boolean true |
False | Boolean false |
โ ๏ธ Miscellaneous Keywords
Option Explicit
Dim total
total = 100
Keyword | Purpose |
---|---|
Option Explicit | Forces variable declaration with Dim |
ByVal / ByRef | Defines parameter passing method |
Class | Begin class definition |
New | Create object instances |
๐ Best Practices for VB Keywords
โ Do:
- Always use
Option Explicit
for clean code - Use
Dim
to declare all variables explicitly - Apply logical operators carefully in conditions
โ Avoid:
- Overwriting keywords as variable names
- Skipping
Set
when assigning object variables - Using
On Error Resume Next
without checkingErr
afterward
๐ Summary โ Recap & Next Steps
VBScript keywords are the building blocks of Classic ASP scripting. They define structure, logic, and control, making your server-side code predictable, readable, and robust.
๐ Key Takeaways:
- Keywords include
If
,Dim
,Function
,Err
,Set
,Nothing
, etc. - Reserved words cannot be used as variable names
- Use them to control flow, declare data, and handle errors effectively
โ๏ธ Real-world Use Cases:
- Structuring login logic
- Declaring constants for configurations
- Handling errors in data processing routines
โ FAQs โ ASP VB Keywords
โ Can I use VB keywords as variable names?
โ No. Reserved words like If
, Function
, Set
, etc., cannot be used as variable names.
โ Is VBScript case-sensitive?
โ
No. VBScript in Classic ASP is not case-sensitive.
โ Whatโs the difference between Null
and Nothing
?
โ
Null
is for data values, while Nothing
is for object references.
Share Now :