VBSCRIPT DATATYPES VBScript (Visual Basic Scripting Edition) is a lightweight scripting language used primarily for web development and automation tasks. It supports several data types for handling different types of data Variant: Default type, can store any kind of data. Integer: Whole numbers (from -32,768 to 32,767). Long: Larger integers (from -2,147,483,648 to 2,147,483,647). Single: Single-precision floating-point numbers. Double: Double-precision floating-point numbers. String: Text or character data. Boolean: Logical values (True or False). Date: Date and time values. Nothing: Object variable with no reference. Empty: Uninitialized variable Variant  Description: In VBScript, all variables are of type Variant by default. A Variant can hold any type of data (e.g., string, integer, date). Dim myVar myVar = "Hello, World!" ' String MsgBox myVar ' Outputs "Hello, World!" myVar = 100 ' Integer MsgBox myVar ' Outputs 100
myVar = #12/25/2024# ' Date MsgBox myVar ' Outputs "12/25/2024" Integer Stores whole numbers between -32,768 and 32,767 Dim num num = 1500 MsgBox num ' Outputs 1500 Long Used for storing larger integers, ranging from -2,147,483,648 to 2,147,483,647. Dim largeNum largeNum = 1234567890 MsgBox largeNum ' Outputs 1234567890 Single Stores single-precision floating-point numbers (decimal values). Dim floatNum floatNum = 3.14159
MsgBox floatNum ' Outputs 3.14159 Double Used to store double-precision floating-point numbers for higher precision. Dim doubleNum doubleNum = 1234567890.987654321 MsgBox doubleNum ' Outputs 1234567890.987654 String Stores a sequence of characters, including text or numbers as text. Dim str str = "Hello, VBScript!" MsgBox str ' Outputs "Hello, VBScript!" Boolean Stores logical values: True or False. Dim isTrue isTrue = True MsgBox isTrue ' Outputs -1 (VBScript treats True as -1) Dim isFalse isFalse = False MsgBox isFalse ' Outputs 0
Date Used to store date and time values. Dim currentDate currentDate = Now ' Get current date and time MsgBox currentDate ' Outputs current date and time Dim specificDate specificDate = #12/25/2024# MsgBox specificDate ' Outputs "12/25/2024" Nothing Represents a variable that has no object reference or value. It is not a data type per se, but used for object variables. Dim obj Set obj = Nothing ' Releases object reference MsgBox IsObject(obj) ' Outputs False Empty Represents an uninitialized variable. It is used to check if a variable has been assigned a value or not. Dim emptyVar MsgBox IsEmpty(emptyVar) ' Outputs True NULL: Represents the absence of a value (usually used with database or object-related operations).
Dim myNullVar myNullVar = Null MsgBox IsNull(myNullVar) ' Outputs True VBScript Operators: Dim a, b, result a = 10 b = 3 result = a + b MsgBox result result = a - b MsgBox result result = a * b MsgBox result result = a / b MsgBox result
result = a b MsgBox result result = a Mod b MsgBox result Comparison Operators Dim a, b a = 10 b = 5 If a = b Then MsgBox "Equal" Else MsgBox "Not Equal" End If If a > b Then MsgBox "a is greater than b" End If Logical Operators
Dim a, b a = True b = False If a And b Then MsgBox "Both are True" Else MsgBox "At least one is False" End If If Not a Then MsgBox "a is False" Else MsgBox "a is True" End If Concatenation Dim firstName, lastName, fullName firstName = "John" lastName = "Doe" fullName = firstName & " " & lastName
MsgBox fullName Type Conversion Operators  These operators are used to convert one data type to another. Operator Description Example CInt Converts to Integer CInt(expression) CDbl Converts to Double CDbl(expression) CStr Converts to String CStr(expression) CDate Converts to Date CDate(expression) CLng Converts to Long CLng(expression) Dim num, strNum num = 3.14 strNum = CStr(num) ' Converts to string MsgBox strNum Dim dateStr, dateVal dateStr = "12/25/2024" dateVal = CDate(dateStr) ' Converts to date MsgBox dateVal Assignment Operators
 These operators are used to assign values to variables. Operator Description Example = Assignment a = b += Add and assign a += b (a = a + b) -= Subtract and assign a -= b (a = a - b) *= Multiply and assign a *= b (a = a * b) /= Divide and assign a /= b (a = a / b) &= Concatenate and assign a &= b (a = a & b) Dim a, b a = 5 b = 3 a += b ' a = a + b, so a becomes 8 MsgBox a Bitwise Operators  These operators are used for bit-level operations. Operator Description Example And Bitwise AND a And b Or Bitwise OR a Or b
Operator Description Example Xor Bitwise XOR a Xor b Not Bitwise NOT Not a Shl Bitwise Shift Left a Shl b Shr Bitwise Shift Right a Shr b Dim a, b, result a = 5 ' 0101 in binary b = 3 ' 0011 in binary result = a And b MsgBox result result = a Or b MsgBox result

VBScript datatypes and control structures.docx

  • 1.
    VBSCRIPT DATATYPES VBScript (VisualBasic Scripting Edition) is a lightweight scripting language used primarily for web development and automation tasks. It supports several data types for handling different types of data Variant: Default type, can store any kind of data. Integer: Whole numbers (from -32,768 to 32,767). Long: Larger integers (from -2,147,483,648 to 2,147,483,647). Single: Single-precision floating-point numbers. Double: Double-precision floating-point numbers. String: Text or character data. Boolean: Logical values (True or False). Date: Date and time values. Nothing: Object variable with no reference. Empty: Uninitialized variable Variant  Description: In VBScript, all variables are of type Variant by default. A Variant can hold any type of data (e.g., string, integer, date). Dim myVar myVar = "Hello, World!" ' String MsgBox myVar ' Outputs "Hello, World!" myVar = 100 ' Integer MsgBox myVar ' Outputs 100
  • 2.
    myVar = #12/25/2024#' Date MsgBox myVar ' Outputs "12/25/2024" Integer Stores whole numbers between -32,768 and 32,767 Dim num num = 1500 MsgBox num ' Outputs 1500 Long Used for storing larger integers, ranging from -2,147,483,648 to 2,147,483,647. Dim largeNum largeNum = 1234567890 MsgBox largeNum ' Outputs 1234567890 Single Stores single-precision floating-point numbers (decimal values). Dim floatNum floatNum = 3.14159
  • 3.
    MsgBox floatNum 'Outputs 3.14159 Double Used to store double-precision floating-point numbers for higher precision. Dim doubleNum doubleNum = 1234567890.987654321 MsgBox doubleNum ' Outputs 1234567890.987654 String Stores a sequence of characters, including text or numbers as text. Dim str str = "Hello, VBScript!" MsgBox str ' Outputs "Hello, VBScript!" Boolean Stores logical values: True or False. Dim isTrue isTrue = True MsgBox isTrue ' Outputs -1 (VBScript treats True as -1) Dim isFalse isFalse = False MsgBox isFalse ' Outputs 0
  • 4.
    Date Used to storedate and time values. Dim currentDate currentDate = Now ' Get current date and time MsgBox currentDate ' Outputs current date and time Dim specificDate specificDate = #12/25/2024# MsgBox specificDate ' Outputs "12/25/2024" Nothing Represents a variable that has no object reference or value. It is not a data type per se, but used for object variables. Dim obj Set obj = Nothing ' Releases object reference MsgBox IsObject(obj) ' Outputs False Empty Represents an uninitialized variable. It is used to check if a variable has been assigned a value or not. Dim emptyVar MsgBox IsEmpty(emptyVar) ' Outputs True NULL: Represents the absence of a value (usually used with database or object-related operations).
  • 5.
    Dim myNullVar myNullVar =Null MsgBox IsNull(myNullVar) ' Outputs True VBScript Operators: Dim a, b, result a = 10 b = 3 result = a + b MsgBox result result = a - b MsgBox result result = a * b MsgBox result result = a / b MsgBox result
  • 6.
    result = a b MsgBox result result = a Mod b MsgBox result Comparison Operators Dim a, b a = 10 b = 5 If a = b Then MsgBox "Equal" Else MsgBox "Not Equal" End If If a > b Then MsgBox "a is greater than b" End If Logical Operators
  • 7.
    Dim a, b a= True b = False If a And b Then MsgBox "Both are True" Else MsgBox "At least one is False" End If If Not a Then MsgBox "a is False" Else MsgBox "a is True" End If Concatenation Dim firstName, lastName, fullName firstName = "John" lastName = "Doe" fullName = firstName & " " & lastName
  • 8.
    MsgBox fullName Type ConversionOperators  These operators are used to convert one data type to another. Operator Description Example CInt Converts to Integer CInt(expression) CDbl Converts to Double CDbl(expression) CStr Converts to String CStr(expression) CDate Converts to Date CDate(expression) CLng Converts to Long CLng(expression) Dim num, strNum num = 3.14 strNum = CStr(num) ' Converts to string MsgBox strNum Dim dateStr, dateVal dateStr = "12/25/2024" dateVal = CDate(dateStr) ' Converts to date MsgBox dateVal Assignment Operators
  • 9.
     These operatorsare used to assign values to variables. Operator Description Example = Assignment a = b += Add and assign a += b (a = a + b) -= Subtract and assign a -= b (a = a - b) *= Multiply and assign a *= b (a = a * b) /= Divide and assign a /= b (a = a / b) &= Concatenate and assign a &= b (a = a & b) Dim a, b a = 5 b = 3 a += b ' a = a + b, so a becomes 8 MsgBox a Bitwise Operators  These operators are used for bit-level operations. Operator Description Example And Bitwise AND a And b Or Bitwise OR a Or b
  • 10.
    Operator Description Example XorBitwise XOR a Xor b Not Bitwise NOT Not a Shl Bitwise Shift Left a Shl b Shr Bitwise Shift Right a Shr b Dim a, b, result a = 5 ' 0101 in binary b = 3 ' 0011 in binary result = a And b MsgBox result result = a Or b MsgBox result