Types of Vbscript Functions
1) Abs Function
Returns the absolute value of a number.
Dim num
num=abs(-50.33)
msgbox num
2) Array Function
Returns a variant containing an Array
Dim A
A=Array("hyderabad","chennai","mumbai")
msgbox A(0)
ReDim A(5)
A(4)="nellore"
msgbox A(4)
3) Asc Function
Returns the ANSI character code corresponding to the first letter in a string.
Dim num
num=Asc("A")
msgbox num
* It returns the value 65 *
4) Chr Function
Returns the character associated with the specified ANSI character code.
Dim char
Char=Chr(65)
msgbox char
* It returns A *
5) CInt Function
Returns an expression that has been converted to a Variant of subtype Integer.
Dim num
num=123.45
myInt=CInt(num)
msgbox MyInt
6) Date Function
Returns the Current System Date.
Dim mydate
mydate=Date
msgbox mydate
7) Day Function
Ex1) Dim myday
myday=Day("17,December,2009")
msgbox myday
Ex2) Dim myday
mydate=date
myday=Day(Mydate)
msgbox myday
8) DateDiff Function
Returns the number of intervals between two dates.
Dim myday
mydate=#02-17-2009#
x=Datediff("d",mydate,Now)
msgbox x
9) Hour Function
Returns a whole number between 0 and 23, inclusive, representing the hour of the day.
Dim mytime, Myhour
mytime=Now
myhour=hour (mytime)
msgbox myhour
10) Join Function
Returns a string created by joining a number of substrings contained in an array.
Dim mystring, myarray(3)
myarray(0)="Chandra "
myarray(1)="Mohan "
myarray(2)="Reddy"
mystring=Join(MyArray)
msgbox mystring
11) Eval Function
Evaluates an expression and returns the result.
12) Time Function
Returns a Variant of subtype Date indicating the current system time.
Dim mytime
mytime=Time
msgbox mytime
13) VarType Function
Returns a value indicating the subtype of a variable.
Dim MyCheck
MyCheck = VarType(300) ' Returns 2.
Msgbox Mycheck
MyCheck = VarType(#10/19/62#) ' Returns 7.
Msgbox Mycheck
MyCheck = VarType("VBScript") ' Returns 8.
Msgbox Mycheck
14) Left Function
Dim MyString, LeftString
MyString = "VBSCript"
LeftString = Left(MyString, 3) ' LeftString contains "VBS".
14) Right Function
Dim AnyString, MyStr
AnyString = "Hello World" ' Define string.
MyStr = Right(AnyString, 1) ' Returns "d".
MyStr = Right(AnyString, 6) ' Returns " World".
MyStr = Right(AnyString, 20) ' Returns "Hello World".
15) Len Function
Returns the number of characters in a string or the number of bytes required to store a variable.
Ex 1): Dim Mystring
mystring=Len("G.C.Reddy")
msgbox mystring
Ex 2): Dim Mystring
Mystring=Inputbox("Enter a Value")
Mystring=Len(Mystring)
Msgbox Mystring
16) Mid Function
Returns a specified number of characters from a string.
Dim MyVar
MyVar = Mid("VB Script is fun!", 4, 6)
Msgbox MyVar
* It Returns ‘Script’ *
17) Timer Function
Returns the number of seconds that have elapsed since 12:00 AM (midnight).
Function myTime(N)
Dim StartTime, EndTime
StartTime = Timer
For I = 1 To N
Next
EndTime = Timer
myTime= EndTime - StartTime
msgbox myTime
End Function
Call myTime(2000)
17) isNumeric Function
Dim MyVar, MyCheck
MyVar = 53
MyCheck = IsNumeric(MyVar)
msgbox MyCheck
MyVar = "459.95"
MyCheck = IsNumeric(MyVar)
msgbox MyCheck
MyVar = "45 Help"
MyCheck = IsNumeric(MyVar)
msgbox MyCheck
* It Returns True/False like Result *
18) Inputbox Function
Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns the contents of the text box.
Dim Input
Input = InputBox("Enter your name")
MsgBox ("You entered: " & Input)
19) Msgbox Function
Displays a message in a dialog box, waits for the user to click a button, and returns a value indicating which button the user clicked.
Dim MyVar
MyVar = MsgBox ("Hello World!", 65, "MsgBox Example")
- Conversions (25)
- Dates/Times (19)
- Formatting Strings (4)
- Input/Output (3)
- Math (9)
- Miscellaneous (3)
- Rounding (5)
- Strings (30)
- Variants (8)
1) Abs Function
Returns the absolute value of a number.
Dim num
num=abs(-50.33)
msgbox num
2) Array Function
Returns a variant containing an Array
Dim A
A=Array("hyderabad","chennai","mumbai")
msgbox A(0)
ReDim A(5)
A(4)="nellore"
msgbox A(4)
3) Asc Function
Returns the ANSI character code corresponding to the first letter in a string.
Dim num
num=Asc("A")
msgbox num
* It returns the value 65 *
4) Chr Function
Returns the character associated with the specified ANSI character code.
Dim char
Char=Chr(65)
msgbox char
* It returns A *
5) CInt Function
Returns an expression that has been converted to a Variant of subtype Integer.
Dim num
num=123.45
myInt=CInt(num)
msgbox MyInt
6) Date Function
Returns the Current System Date.
Dim mydate
mydate=Date
msgbox mydate
7) Day Function
Ex1) Dim myday
myday=Day("17,December,2009")
msgbox myday
Ex2) Dim myday
mydate=date
myday=Day(Mydate)
msgbox myday
8) DateDiff Function
Returns the number of intervals between two dates.
Dim myday
mydate=#02-17-2009#
x=Datediff("d",mydate,Now)
msgbox x
9) Hour Function
Returns a whole number between 0 and 23, inclusive, representing the hour of the day.
Dim mytime, Myhour
mytime=Now
myhour=hour (mytime)
msgbox myhour
10) Join Function
Returns a string created by joining a number of substrings contained in an array.
Dim mystring, myarray(3)
myarray(0)="Chandra "
myarray(1)="Mohan "
myarray(2)="Reddy"
mystring=Join(MyArray)
msgbox mystring
11) Eval Function
Evaluates an expression and returns the result.
12) Time Function
Returns a Variant of subtype Date indicating the current system time.
Dim mytime
mytime=Time
msgbox mytime
13) VarType Function
Returns a value indicating the subtype of a variable.
Dim MyCheck
MyCheck = VarType(300) ' Returns 2.
Msgbox Mycheck
MyCheck = VarType(#10/19/62#) ' Returns 7.
Msgbox Mycheck
MyCheck = VarType("VBScript") ' Returns 8.
Msgbox Mycheck
14) Left Function
Dim MyString, LeftString
MyString = "VBSCript"
LeftString = Left(MyString, 3) ' LeftString contains "VBS".
14) Right Function
Dim AnyString, MyStr
AnyString = "Hello World" ' Define string.
MyStr = Right(AnyString, 1) ' Returns "d".
MyStr = Right(AnyString, 6) ' Returns " World".
MyStr = Right(AnyString, 20) ' Returns "Hello World".
15) Len Function
Returns the number of characters in a string or the number of bytes required to store a variable.
Ex 1): Dim Mystring
mystring=Len("G.C.Reddy")
msgbox mystring
Ex 2): Dim Mystring
Mystring=Inputbox("Enter a Value")
Mystring=Len(Mystring)
Msgbox Mystring
16) Mid Function
Returns a specified number of characters from a string.
Dim MyVar
MyVar = Mid("VB Script is fun!", 4, 6)
Msgbox MyVar
* It Returns ‘Script’ *
17) Timer Function
Returns the number of seconds that have elapsed since 12:00 AM (midnight).
Function myTime(N)
Dim StartTime, EndTime
StartTime = Timer
For I = 1 To N
Next
EndTime = Timer
myTime= EndTime - StartTime
msgbox myTime
End Function
Call myTime(2000)
17) isNumeric Function
Dim MyVar, MyCheck
MyVar = 53
MyCheck = IsNumeric(MyVar)
msgbox MyCheck
MyVar = "459.95"
MyCheck = IsNumeric(MyVar)
msgbox MyCheck
MyVar = "45 Help"
MyCheck = IsNumeric(MyVar)
msgbox MyCheck
* It Returns True/False like Result *
18) Inputbox Function
Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns the contents of the text box.
Dim Input
Input = InputBox("Enter your name")
MsgBox ("You entered: " & Input)
19) Msgbox Function
Displays a message in a dialog box, waits for the user to click a button, and returns a value indicating which button the user clicked.
Dim MyVar
MyVar = MsgBox ("Hello World!", 65, "MsgBox Example")