HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to Classic ASPVariablesStringsConditions (If / Select Case)Loops (For / Do While)Form and Request
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
✍️ Text & Number
🔁 Condition & Loop
🧩 Functions & Forms
Classic ASP›Conditions (If / Select Case)

Conditions (If / Select Case)

Decision making with If-Then-Else and multi-way selection with Select Case.

Simple enough for a 5-year-old to understand

If / Else

Example code
1
Dim number
2
number = 7
3
If number Mod 2 = 0 Then
Mod returns the remainder.
ConditionMod returns the remainder.
4
Response.Write "even"
If the condition is true.
Output / InputIf the condition is true.
5
Else
6
Response.Write "odd"
If the condition is false.
Output / InputIf the condition is false.
7
End If
The block ends here.
ConditionThe block ends here.
ConditionOutput / Input
💡 Hint: Equality checks in VBScript are also done with a single equals sign.

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (1 left)

1.How is an If block closed in VBScript?

About this topic

In VBScript, conditions are written with if, then, and an end line. Single-statement conditions can also be written on the same line without an end line, but this format turns into a silent error when lines are added later.

Comparison and assignment use the same sign; the context determines which one it is. The equals sign inside a condition is a comparison, and at the beginning of an expression, it is an assignment. This requires care when reading, but the compiler experiences no ambiguity.

The most important detail is this: VBScript does not perform short-circuit evaluation. Both sides of a compound condition are evaluated. Therefore, combining an "is the object present" check with access in the same condition does not work and produces an error.

What you will learn

  • Condition block structure
  • Single-line condition risk
  • Logical operators
  • That short-circuiting is not performed
  • Multi-branch selection structure

Who is this for?

  • Those writing decision logic in ASP pages
  • Those getting null value errors
  • Those tracing the flow in legacy code

When to use?

Null or object checks must be written in nested separate conditions; since there is no short-circuiting, combining them in a single line is not safe.

If you are branching based on many constant values of a variable, a selection structure is much more readable than long chains of conditions.

Common mistakes

Wrong

<%
Option Explicit
Dim kayit
Set kayit = Nothing
If Not kayit Is Nothing And kayit.Fields("ad") <> "" Then
  Response.Write "full"
End If
%>

VBScript evaluates both sides of a compound condition; even though the object has not been assigned, property access is attempted and a runtime error occurs. The guard check must be done in a separate condition block before the inner access. Expecting short-circuiting is the most common mistake.

Correct

<%
Option Explicit
Dim kayit
Set kayit = Nothing
If Not kayit Is Nothing Then
  If kayit.Fields("ad") <> "" Then
    Response.Write "full"
  End If
End If
%>

Wrong

<%
Option Explicit
Dim yas
yas = 20
If yas >= 18 Then Response.Write "adult"
                  Response.Write " - registered"
%>

In the single-line condition format, only the expression on the same line is bound to the condition; the second line runs in all cases, even if indented. If you are going to add a second expression, you must switch to the block format and write an end line.

Correct

<%
Option Explicit
Dim yas
yas = 20
If yas >= 18 Then
  Response.Write "adult"
  Response.Write " - registered"
End If
%>

Wrong

<%
Option Explicit
Dim rol
rol = Request.Form("rol")
If rol = "admin" Then
  Response.Write "manager"
Else If rol = "editor" Then
  Response.Write "editor"
End If
%>

Chained condition is written as a single word; when written as two words, this starts a new and separate condition block, and each requires its own end line. It gives a page syntax error due to a missing end line. Two visually similar spellings carry completely different meanings.

Correct

<%
Option Explicit
Dim rol
rol = Request.Form("rol")
If rol = "admin" Then
  Response.Write "manager"
ElseIf rol = "editor" Then
  Response.Write "editor"
End If
%>

Frequently asked questions

Is there really no short-circuit evaluation?

No. VBScript's logical operators evaluate both sides. The way to overcome this behavior is to split the checks into nested conditions or to first calculate a helper variable and test it.

Is text comparison case-sensitive?

By default, it is sensitive. To ignore case, you need to convert both sides to the same format or use a function that takes a comparison mode. Remember that conversion for Turkish characters depends on the server's language setting.

How does the selection structure work?

It compares an expression with multiple values; the matching branch runs, and the structure ends. Several values can be listed with commas in a branch, and a section to run if none match can be defined.

Summary

Condition blocks close with an end line.

A single-line condition binds only one expression.

Chained condition is written as a single word.

Short-circuit evaluation is not performed.

Guard checks must be written nested.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code