To Output message to HTML
document.write("text message") instruction:-
This statement outputs passed text messages to HTML web page
Example:
<html>
<body><script type="text/vbscript">document.write("text message")</script></p>
VBscript variables
"Dim" is used to declare variables as shown below
Example:
Dim variable1, variable2
Arrays are declared as follows
Example ---> Dim vararry(5)
Arrays starts from element 0, so in this example vararry contains 6 elements
VBscript Conditional Statements
Conditional statements are "if --> Then --> end If" , "if --> Then ---> Elesif ---> end If" , "Select case"
Example for "If then End If"
If count > 8 then
vara = count + 1
End if
Example for "If then Elseif End if"
If count = 8 then
vara = count + 1
ElseIf count = 9 then
vara = count + 2
ElseIf count = 10 then
vara = count + 3
Else
vara = count
End If
Example for "Select Case"
Select Case count
Case 8vara = count + 1
Case 9vara = count + 2
Case elsevara = count
End Select
VBscript Loop Statements
Loop statements are "Do While---loop" , "Do Until---loop", "Do---loop while" , "Do--loop until"
"While---wend" , "For---next", "For Each---next"
Do While--loop statement:-
Example:
Do While count > 5
codes
Loop
Do Until--loop statement:-
Example:
Do Until count < 5
codes
Loop
Do --loop While statement --> executes until condition becomes false :-
Example:
Do
codes
Loop While count > 5
Do--loop until statement --> executes until condition becomes true:-
Example:
Do
codes
Loop Until count < 5
For--next statement:-
Example:
For i = 1 to 10
  codes
Next
For--each--next statement:-
Example:
For each i in vararry
  codes
Next
VBscript Procedures
Procedure example
Sub subproc1()
codes
End Sub
Another example
Sub subproc1(parm1, parm2)
codes
End Sub
Functions example
Function func1()
codes
func1=assign value
End Function
Functions with parameters example
Function func1(parm1, parm2)
codes
func1=assign value
End Function
Calling function example
Call sample=func1() or a="text1" & func1()
Calling proc example
Call proc1(parm1) or proc1 parm1
VBscript builtin Functions
Following are different builtin functions
Date and time functions
Date -- Returns current system date
Example: document.write(date)
DateAdd(interval,number,date) - given time interval added and return the date value
Example: DateAdd("d",1,"02-Jan-09") adds one day, result is 3rd Jan 2009
DateDiff(interval,date1,date2[,firstdayofweek[,firstweekofyear]]) - return difference between 2 given intervals
example: DateDiff("m","1/5/2009","2/5/2009") results 1 - 1 month difference
Datepart - results in specified part of a given date
DateSerial - the date for a specified year, month, and day
DateValue - returns the date
Day - a number of the day of the month
FormatDateTime - formatted as a date or time
Hour - Hour of the day
IsDate - to check evaluated expression can be converted to date
Minute - Minute of the hour
Month - Month of the year
MonthName - returns month name
Now - results in current system date and time
Second - second of the minute
Time - current system time
Timer - number of seconds
TimeSerial - time for specific hour, minute and second
TimeValue - returns a time
weekday - day of the week(1 to 7)
weekdayname - weekday name of given day
Year - number belongs to year in given date
String functions
InStr - position of the first occurrence of one string within another. The search begins at the first character of the string
InStrRev - position of the first occurrence of one string within another. The search begins at the last character of the string
LCase - Converts a specified string to lowercase
Left - Returns a specified number of characters from the left side of a string
Len - number of characters in a string
LTrim - Removes spaces on the left side of a string
RTrim - Removes spaces on the right side of a string
Trim - Removes spaces on both the left and the right side of a string
Mid - Returns a specified number of characters from a string
Replace - Replaces a specified part of a string with another string a specified number of times
Right - specified number of characters from the right side of a string
Space - string that consists of a specified number of spaces
StrComp - Compares two strings and returns a value that represents the result of the comparison
String - a string that contains a repeating character of a specified length
StrReverse - Reverses a string
UCase - Converts a specified string to uppercase
Arithmetic functions
Abs - absolute value of a given number
Atn - arctangent of a given number
Cos - cosine of a given number (angle)
Exp - e raised to a power
Hex - hexadecimal value of a given number
Int - integer part of a given number
Fix - integer part of a given number
Log - natural logarithm of a given number
Oct - octal value of a given number
Rnd - random number less than 1 but greater or equal to 0
Sgn - integer that indicates the sign of a given number
Sin - sine of a given number (angle)
Sqr - square root of a given number
Tan - tangent of a given number (angle)
Additional functions
CreateObject - Creates an object of a specified type
Eval - Evaluates an expression and returns the result
GetLocale - current locale ID
GetObject - reference to an automation object from a file
GetRef - to connect a VBScript procedure to a DHTML event on your pages
InputBox - Displays a dialog box, where the visitor can write some input and/or click on a button, and returns the contents
IsEmpty - Boolean value that indicates whether a specified variable has been initialized or not
IsNull - Boolean value that indicates whether a specified expression contains no valid data (Null)
IsNumeric - Boolean value that indicates whether a specified expression can be evaluated as a number
IsObject -Boolean value that indicates whether the specified expression is an automation object
LoadPicture- picture object. Available only on 32-bit platforms
MsgBox - message box, waits for the user to click a button, and returns a value that indicates which button the user clicked
RGB - number that represents an RGB color value
Round - Rounds a number
ScriptEngine - scripting language in use
ScriptEngineBuildVersion - build version number of the scripting engine in use
ScriptEngineMajorVersion - major version number of the scripting engine in use
ScriptEngineMinorVersion - minor version number of the scripting engine in use
SetLocale - Sets the locale ID and returns the previous locale ID
TypeName - subtype of a specified variable
VarType - value indicating subtype of a given parameter/value
Conversion functions
Asc - converts first letter in a string to ANSI code
Chr - converts specified ANSI code to a character
CInt - converts expression to type integer
CLng - converts expression to type long
Cstr - converts expression to type string
Hex - returns hexadecimal value of given number
Oct - return octal format of given number