Friday, June 11, 2010

VarType Function

' To check the Variable type using Vb Scripts
'vbArray
myArray = Array(20)
If VarType(myArray) And vbArray Then MsgBox " Array Variable"

'vbBoolean
myBoolean = True
If VarType(myBoolean) And vbBoolean Then MsgBox "Boolean Variable"

'vbnull
myNull = Null
If VarType(myNull) And vbNull Then MsgBox "Null Variable"

'vbEmpty
myEmpty = Empty
If VarType(myEmpty) And vbEmpty Then MsgBox "Empty Variable"

'vbDecimal
myDecimal = 23.23423
If VarType(myDecimal) And vbDecimal Then MsgBox "Decimal Variable"

VbInteger 
myInteger = 123
If VarType(myInteger) And vbInteger Then MsgBox "Integer Variable"

'vbCurrency
myCurrency = 23323
If VarType(myCurrency) And vbCurrency Then MsgBox "Currency Variable"

vbSingle 
mySingle = 2.344
If VarType(mySingle) And vbSingle Then MsgBox "Single Variable"

VbDouble 
myDouble = 92349.3405034
If VarType(myDouble) And vbdouble Then MsgBox "Double Variable"

VbLong
myLong = 1243242343423#
If VarType(myLong) And vbLong Then MsgBox "Long Variable"

VbDate
MyDate = Date
If VarType(MyDate) And vbDate Then MsgBox "Date Variable"

FormatDatetime Function

Syntax:
FormatDateTime(Date[,NameFormat])

Name of the Format:
vbGeneralDate vbLongDate vbShortDate vbLongTime VbShortTime

Code:
Dim TDate, MyReturn
TDate = Now
MyReturn = FormatDateTime(TDate, vbGeneralDate)
MsgBox MyReturn

FormatPercentage Function

The function returns an expression formatted as a percentage (multiplied by 100) with a trailing % character.

Dim MyValue, MyReturn
MyValue = 3459459.345
MyReturn = FormatPercent(MyValue, 1, vbUseDefault, vbUseDefault, vbUseDefault)
MsgBox MyReturn

MyReturn = FormatPercent(1000.578) ' Returns 57.80%
MyReturn = FormatPercent(1000.578, 1) ' Returns 57.8%
MyReturn = FormatPercent(1000.578, 3) ' Returns 57.800%
MyReturn = FormatPercent(.578,,True) ' Returns 57.80%
MyReturn = FormatPercent(.578,,False) ' Returns 57.80%
MyReturn = FormatPercent(-1000.578,,,True) ' Returns (57.80%)
MyReturn = FormatPercent(-1000.578,,,False) ' Returns -57.80%
MyReturn = FormatPercent(1000000.578,,,,True) ' Returns 57.80%
MyReturn = FormatPercent(1000000.578,,,,False) ' Returns 57.80%

FormatNumber Function

Returns an expression formatted as a number

Dim MyValue, MyReturn
MyValue = 3459459.3453454
MyReturn = FormatNumber(MyValue, 10, vbUseDefault, vbUseDefault, vbUseDefault)
MsgBox MyReturn

MyReturn = FormatNumber(1000.578) ' Returns 1,000.58
MyReturn = FormatNumber(1000.578, 1) ' Returns 1,000.6
MyReturn = FormatNumber(1000.578, 3) ' Returns 1,000.578
MyReturn = FormatNumber(.578,,True) ' Returns 0.58
MyReturn = FormatNumber(.578,,False) ' Returns $.58
MyReturn = FormatNumber(-1000.578,,,True) ' Returns (1,000.58)
MyReturn = FormatNumber(-1000.578,,,False) ' Returns -1,000.58
MyReturn = FormatNumber(1000000.578,,,,True) ' Returns 1,000,000.58
MyReturn = FormatNumber(1000000.578,,,,False) ' Returns 1000000.58

FormatCurrency Function

Returns an expression formatted as a currency value using the currency symbol defined in the computer's control panel.
Dim MyValue, MyReturn
MyValue = 3459459.3453454
MyReturn = FormatCurrency(MyValue, 6, vbUseDefault, vbUseDefault, vbUseDefault)
MsgBox MyReturn

Result like

MyReturn = FormatCurrency(1000.578) ' Returns $1,000.58
MyReturn = FormatCurrency(1000.578, 1) ' Returns $1,000.6
MyReturn = FormatCurrency(1000.578, 3) ' Returns $1,000.578
MyReturn = FormatCurrency(.578,,True) ' Returns $0.58
MyReturn = FormatCurrency(.578,,False) ' Returns $.58
MyReturn = FormatCurrency(-1000.578,,,True) ' Returns ($1,000.58)
MyReturn = FormatCurrency(-1000.578,,,False) ' Returns -$1,000.58
MyReturn = FormatCurrency(1000000.57,,,,True) ' Returns $1,000,000.57
MyReturn = FormatCurrency(1000000.57,,,,False) ' Returns $1000000.57

Rnd Function

Dim MyValue, MyReturn
MyReturn = Rnd(100)
MsgBox MyReturn

ASC -String Manipulation Function

It represents the character code or Unicode of the first character of the string.

Dim myval
myval = "Z"
MyReturn = Asc(myval)
MsgBox MyReturn

Chr Function

Dim myval, MyReturnchr,
MyReturnchr = Chr(97)
MsgBox "CHR Code Is:" & MyReturnchr

Instr Function

Dim MyVal1, MyVal2
MyVal1 = "Welcome to India"
MyVal2 = "India"
MyInstr = InStr(10, MyVal1, "India", 0)
MsgBox MyInstr

Instrrev Function

Dim MyVal1, MyVal2,MyInstrRev
MyVal1 = "Welcome to India"
MyVal2 = "India"
MyInstrRev = InStrRev(MyVal1, "India",10,0)
MsgBox MyInstrRev

String Function

The String function returns a repeating character string of the length specified.
Dim MyReturn
MyReturn = String(16, "Automation Testing")
MsgBox MyReturn

ABS Function

It will return the absolute value or positive value of the number
Dim MyValue, MyReturn
MyValue = -34.2345325
MyReturn = Abs(MyValue)
MsgBox MyReturn

Atn Function

It returns arctangent of the number
Dim MyValue, MyReturn
MyValue = 3
MyReturn = Atn(MyValue)
MsgBox MyReturn

COS Function

Dim MyValue, MyReturn
MyValue = 3
MyReturn = Cos(MyValue)
MsgBox MyReturn

Sin Function

The sin of an angle
Dim MyValue, MyReturn
MyValue = 3
MyReturn = Sin(MyValue)
MsgBox MyReturn

Tan Function

It returns the tangent of an angle
Dim MyValue, MyReturn
MyValue = 3
MyReturn = Tan(MyValue)
MsgBox MyReturn

Log Function

Function returns the natural logarithm of the number
Dim MyValue, MyReturn
MyValue = 3
MyReturn = Log(MyValue)
MsgBox MyReturn

Exp Function

The Exp function returns the antilogarithm of a number
Dim MyValue, MyReturn
MyValue = 3
MyReturn = Exp(MyValue)
MsgBox MyReturn

Sqr Function

It returns calculates the square root of the given number
Dim MyValue, MyReturn
MyValue = 3
MyReturn = Sqr(MyValue)
MsgBox MyReturn

Int Function

Function returns the integer portion of the number
Dim MyValue, MyReturn
MyValue = 3.653
MyReturn = Int(MyValue)
MsgBox MyReturn

MyInt = Int(99.8) ' Returns 99.
MyInt = Int(-99.8) ' Returns -100.
MyInt = Int(-99.2) ' Returns -100.
MyInt = Int(6.83227) ' Returns 6
MyInt = Int(6.23443) ' Returns 6
MyInt = Int(-6.13443) ' Returns -7
MyInt = Int(-6.93443) ' Returns -7

Fix Function

The Fix function returns the integer part of a specified number.
Dim MyValue, MyReturn
MyValue = 3.653
MyReturn = Fix(MyValue)
MsgBox MyReturn
It may return like
nFix = Fix(99.2) ' Returns 99.
nFix = Fix(-99.8) ' Returns -99.
nFix = Fix(-99.2) ' Returns -99.
nFix = Fix(6.83227) ' Returns 6
nFix = Fix(6.23443) ' Returns 6
nFix = Fix(-6.13443) ' Returns -6
nFix = Fix(-6.93443) ' Returns -6

Hex function

Returns a string that represents the hexadecimal value of a specified number.

Dim MyValue, MyReturn
MyValue = 3.653
MyReturn = Hex(MyValue)
MsgBox MyReturn

Oct function

Dim MyValue, MyReturn
MyValue = 3.653
MyReturn = Oct(MyValue)
MsgBox MyReturn

Sgn Function

Dim MyValue, MyReturn
MyValue = 3.653
MyReturn = sgn(MyValue)
MsgBox MyReturn

Round Function

The Round function rounds a given number to a specified number of decimal places
Dim MyValue, MyReturn
MyValue = 524324.899
MyReturn = Round(MyValue, 1)
MsgBox MyReturn