What message does this show? Option Explicit · Dim i, total, s · total = 0 · For i = 2 To 11 Step 3 / total = total + i Mod 4 / Next · s = "Total=" & total & ", " & 17 \ 5 & ", " & 2 ^ 3 · MsgBox s
VBScript is Microsoft's lightweight scripting language derived from Visual Basic. It ran client-side only in Internet Explorer and server-side in classic ASP and Windows Script Host. One Variant type, & concatenation, \ integer division, ByRef by default and MsgBox are its exam signatures.
<script type="text/vbscript"> (or language="VBScript"); works only in Internet Explorer. Comments start with ' or Rem; the language is case-insensitive.Name a, b or Call Name(a, b).VBScript (Visual Basic Scripting Edition) was released by Microsoft in 1996 with Internet Explorer 3.0 as a lightweight, interpreted subset of Visual Basic / VBA. It runs inside a script host through the Windows scripting engine vbscript.dll. Three hosts mattered:
| Host | Side | How it is used |
|---|---|---|
| Internet Explorer | Client | <script type="text/vbscript"> in a web page — IE only; other browsers ignore it |
| Classic ASP (IIS) | Server | Code between <% … %> builds the HTML; VBScript was ASP's default language |
| Windows Script Host | Desktop / admin | Stand-alone .vbs files run with wscript.exe (GUI) or cscript.exe (console) for automation |
| HTA, Office, others | Desktop | HTML Applications (.hta), Outlook forms, old SQL Server DTS packages |
<html>
<head>
<script type="text/vbscript">
' a procedure named Control_Event is wired to that event automatically in IE
Sub btnGreet_OnClick()
Dim name
name = InputBox("Your name?", "KSHB portal")
If name <> "" Then
MsgBox "Welcome, " & name & "!", vbInformation, "KSHB portal"
End If
End Sub
</script>
</head>
<body>
<input type="button" name="btnGreet" value="Greet me">
</body>
</html><%@ Language="VBScript" %>
<%
' classic ASP: runs on the IIS server; the browser receives only the HTML it writes
Dim h ' not "hour": names are case-insensitive and would hide Hour()
h = Hour(Now())
If h < 12 Then
Response.Write "<p>Good morning!</p>"
Else
Response.Write "<p>Good afternoon!</p>"
End If
%>
<p>Server time: <%= Now() %></p>MsgBox, msgbox and MSGBOX are the same; so are variable names._ (space + underscore) to continue a long line and : to put two statements on one line.' or the keyword Rem.End If, Next, Loop, Wend, End Sub, End Function, End Select.VBScript has exactly one data type, the Variant. A Variant holds any kind of value and remembers its subtype, converting automatically when needed: x = 5 makes an Integer, x = "5" a String, x = #12/03/2026# a Date. The subtype can be inspected with VarType(x) (a number) or TypeName(x) (a name).
| Subtype | Holds | VarType value |
|---|---|---|
| Empty | Uninitialised: 0 in numbers, "" in strings | 0 (vbEmpty) |
| Null | Deliberately no valid data | 1 (vbNull) |
| Integer | −32,768 to 32,767 | 2 (vbInteger) |
| Long | About ±2.1 billion | 3 (vbLong) |
| Single / Double | Floating-point numbers | 4 / 5 |
| Currency | Fixed-point money values | 6 |
| Date | Date and time | 7 (vbDate) |
| String | Text, up to about 2 billion characters | 8 (vbString) |
| Object | A reference to an object | 9 (vbObject) |
| Error, Boolean, Byte | Error number; True/False; 0–255 | 10, 11, 17 |
| Array | Added to the element type | 8192 + type (Variant array = 8204) |
Dim name declares a variable. Inside a Sub or Function it has procedure-level (local) scope and lives only while the procedure runs; outside any procedure it has script-level scope.Public and Private (script level only) control visibility across scripts; Const RATE = 0.05 declares a constant.Option Explicit, as the first statement of the script, makes every variable require a Dim — a misspelt name then raises 'Variable is undefined' instead of silently creating a new Empty variable.CInt(True) is −1.Option Explicit
Dim marks(4) ' 5 elements: marks(0) … marks(4)
marks(0) = 72 : marks(4) = 91
MsgBox UBound(marks) ' 4 — the upper bound, not the count; LBound is 0
Dim grid(2, 3) ' 2-D: 3 rows × 4 columns = 12 elements
Dim names() ' dynamic array, size decided later
ReDim names(2)
names(0) = "Kollam"
ReDim Preserve names(5) ' grow it; Preserve keeps the existing values
Dim districts
districts = Array("Kollam", "Kochi", "Thrissur") ' Array() returns a Variant array
MsgBox districts(1) ' Kochi
MsgBox TypeName(districts) & " " & VarType(districts) ' Variant() 8204| Category | Operators (highest precedence first) | Examples |
|---|---|---|
| Arithmetic | ^ power · unary − · multiply and / · \ integer division · Mod · + - | 2 ^ 10 = 1024 · 17 / 5 = 3.4 · 17 \ 5 = 3 · 17 Mod 5 = 2 |
| Concatenation | & | "Units: " & 120 = "Units: 120" |
| Comparison | = <> < > <= >= and Is (object references) | x <> 0 means x is not 0 |
| Logical | Not · And · Or · Xor · Eqv · Imp | If age >= 18 And Not barred Then |
& always concatenates, converting numbers to text. + adds when either operand is a number ("5" + 3 = 8) and concatenates only when both are strings ("5" + "3" = "53"); "a" + 3 is a Type mismatch error. Prefer & for strings.&, "Total: " & 2 + 3 gives "Total: 5".\ rounds both operands to whole numbers, divides and drops the fraction; Mod gives the remainder.= is both assignment and comparison — the meaning comes from the position: x = 5 as a statement assigns; If x = 5 Then compares; ok = (x = 5) stores True or False.If marks >= 90 Then
grade = "A"
ElseIf marks >= 75 Then ' one word: ElseIf
grade = "B"
Else
grade = "C"
End If
If grade = "A" Then MsgBox "Distinction" ' single-line If needs no End If
Select Case district
Case "Kollam", "Thiruvananthapuram" ' a list of values
zone = "South"
Case "Ernakulam", "Thrissur"
zone = "Central"
Case Else
zone = "North"
End SelectFor i = 1 To 10 Step 3 ' i = 1, 4, 7, 10 (Step may be negative)
total = total + i
Next
For Each d In Array("Kollam", "Kochi", "Thrissur")
list = list & d & " "
Next
Do While n > 0 ' tested first: may run zero times
n = n - 1
Loop
Do
tries = tries + 1
If tries = 5 Then Exit Do ' leave the loop early
Loop Until ok ' tested last: runs at least once
While x < 5 ' older form; there is no Exit While
x = x + 1
WendDo While cond … Loop and Do Until cond … Loop test before each pass; Do … Loop While cond and Do … Loop Until cond test after, so they run at least once.Exit For, Exit Do, Exit Sub and Exit Function leave the structure immediately.For i = 10 To 1 Step -4 runs with i = 10, 6, 2 — three passes; with a positive step and start > end the body never runs.Select Case accepts only lists of values. Visual Basic forms such as Case 1 To 10 and Case Is > 50 are not supported; the usual workaround is Select Case True followed by Case marks >= 90, Case marks >= 75 and so on.Function Area(length, width)
Area = length * width ' return a value by assigning to the function's name
End Function
Sub ShowArea(l, w)
MsgBox "Area = " & Area(l, w)
End Sub
ShowArea 10, 20 ' calling a Sub: no parentheses ...
Call ShowArea(10, 20) ' ... or Call with parentheses
a = Area(5, 4) ' a Function used in an expression needs parenthesesSub … End SubName a, b or Call Name(a, b)btnSave_OnClick)Function … End Functionx = Name(a, b)Arguments are passed ByRef (by reference) by default: the procedure works on the caller's variable itself, so changes are visible afterwards. Writing ByVal passes a copy instead. A subtle rule: wrapping an argument in its own parentheses turns it into an expression, so it is passed by value even to a ByRef parameter.
Sub Bump(ByRef n, ByVal m)
n = n + 1
m = m + 1
End Sub
Dim x, y
x = 1 : y = 1
Bump x, y ' x becomes 2 (ByRef); y stays 1 (ByVal copy)
Bump (x), y ' (x) is an expression, so a copy is passed: x stays 2
MsgBox x & " " & y ' 2 1MsgBox(prompt, buttons, title) shows a dialog and returns which button was pressed. The buttons argument is a sum of a button set, an icon and optionally a default button. InputBox(prompt, title, default) shows a text box and returns the typed string — a zero-length string if the user clicks Cancel.
| Buttons argument | Value | Return value | Value |
|---|---|---|---|
| vbOKOnly | 0 | vbOK | 1 |
| vbOKCancel | 1 | vbCancel | 2 |
| vbAbortRetryIgnore | 2 | vbAbort | 3 |
| vbYesNoCancel | 3 | vbRetry | 4 |
| vbYesNo | 4 | vbIgnore | 5 |
| vbRetryCancel | 5 | vbYes | 6 |
| vbCritical / vbQuestion / vbExclamation / vbInformation | 16 / 32 / 48 / 64 | vbNo | 7 |
| vbDefaultButton2 / vbDefaultButton3 | 256 / 512 |
| Group | Functions (examples on t = "Kerala State Housing Board") |
|---|---|
| String | Len(t) = 26 · Left(t, 6) = "Kerala" · Right(t, 5) = "Board" · Mid(t, 8, 5) = "State" (1-based) · InStr(t, "Housing") = 14 (0 if absent) · UCase, LCase, Trim, LTrim, RTrim · Replace(t, " ", "-") · StrReverse("KSHB") = "BHSK" · Asc("A") = 65, Chr(65) = "A" |
| Arrays | Split(t, " ") → 4-element array (UBound 3) · Join(arr, ", ") · UBound, LBound, IsArray, Erase |
| Conversion | CInt("42") · CLng · CDbl("3.14") · CStr(42) · CBool(0) = False · CDate · CInt(2.5) = 2 and CInt(3.5) = 4 (round half to even) · Int(-2.5) = −3 but Fix(-2.5) = −2 |
| Checks | IsNumeric("42") = True · IsDate("31/02/2026") = False · IsEmpty, IsNull, IsObject |
| Date and time | Date, Time, Now · Year(Date), Month, Day, Weekday (1 = Sunday), Hour · DateAdd("d", 30, Date) · DateDiff("d", #1/1/2026#, #3/1/2026#) = 59 · MonthName(12) = "December" |
| Maths | Abs, Sqr (square root), Round(2.567, 2) = 2.57, Rnd (0 ≤ value < 1, seed with Randomize), Sgn, Exp, Log, Hex, Oct |
On Error Resume Next ' on an error, carry on with the next statement
Dim result
result = 10 / 0
If Err.Number <> 0 Then
MsgBox "Error " & Err.Number & ": " & Err.Description ' Error 11: Division by zero
Err.Clear ' reset the Err object
End If
On Error GoTo 0 ' switch normal error handling back on
Randomize ' seed the generator
Dim dice
dice = Int(6 * Rnd + 1) ' a random whole number 1–6| Aspect | JavaScript | VBScript |
|---|---|---|
| Origin | Netscape, 1995; ECMAScript standard | Microsoft, 1996; proprietary |
| Browser support | Every browser | Internet Explorer only — now retired |
| Case sensitivity | Case-sensitive | Case-insensitive |
| Types | Several types (number, string, boolean, object…) | One Variant type with subtypes |
| Blocks | Braces { }, optional semicolons | Keywords: End If, Next, Loop, End Sub |
| Concatenation | + | & (and +) |
| Assignment / equality | = vs == / === | = for both |
| Comments | // and /* */ | ' and Rem |
| Procedures | function, returns with return | Sub and Function; return by assigning to the name |
| Error handling | try / catch / finally | On Error Resume Next + Err object |
| Dialogs | alert, confirm, prompt | MsgBox, InputBox |
| Server side | Node.js | Classic ASP |
Try the problem first, then reveal the working one step at a time.
What message does this show? Option Explicit · Dim i, total, s · total = 0 · For i = 2 To 11 Step 3 / total = total + i Mod 4 / Next · s = "Total=" & total & ", " & 17 \ 5 & ", " & 2 ^ 3 · MsgBox s
Write code that asks 'Delete scheme?' with Yes and No buttons, a question-mark icon, No as the default button and the title KSHB, and deletes only if Yes is pressed. What number is passed as the buttons argument, and what does MsgBox return for each button?
s = " Kerala State Housing Board " and t = Trim(s). Evaluate Len(t), Left(t, 6), Mid(t, 8, 5), InStr(t, "Housing"), Right(t, 5), UBound(Split(t, " ")) and Replace(t, " ", "-").
How many times does each loop body run, and what is the final value? (a) For i = 10 To 1 Step -4 (b) n = 0 : Do Until n >= 7 : n = n + 3 : Loop (c) n = 10 : Do : n = n + 1 : Loop While n < 5
Write a VBScript Function Category(income) that returns "EWS" up to ₹3,00,000, "LIG" up to ₹6,00,000 and "MIG" above that, using Select Case. Then show how to call it and display the result.
Rewrite this JavaScript in VBScript: var total = 0; for (var i = 1; i <= 5; i++) { if (i % 2 == 0) { total += i; } } alert("Sum of evens: " + total);
Give TypeName() for each value: 5, 40000, 3.14, "5", True, Now, an uninitialised variable, and Array(1, 2).
Dim a(5) gives six elements (0 to 5); the number in brackets is the upper bound, not the count.= is both assignment and comparison; <> (not !=) means not equal.\ is integer division and / is ordinary division: 7 \ 2 = 3 but 7 / 2 = 3.5.On Error Resume Next and On Error GoTo 0 only — no On Error GoTo label, no Try…Catch.ShowArea(10, 20) without Call is a syntax error ('Cannot use parentheses when calling a Sub'); write ShowArea 10, 20 or Call ShowArea(10, 20).10 questions. 70 % passes the topic quiz (+30 XP, +20 more for 100 %). Exam scoring: +1 correct, −⅓ wrong.
Modelled on real KPSC questions (reworded) with the same concept and answer; each links to its original paper.