VB Script Procedures and Functions

1
102
Spread the love
  • 15
  • 23
  • 18
  • 18
  •  
  •  
  •  
  •  
  •  
  •  
    74
    Shares

Example:

Dim val
val=" VB Script"
x=Trim(val)
msgbox x
x=Len(x)
msgbox x
val=" 100"
x=Trim(val)
msgbox x
x=Len(x)
msgbox x
val=" 2#$%^"
x=Trim(val)
msgbox x
x=Len(x)
msgbox x
val=" VB Script "
x=Trim(val)
msgbox x
x=Len(x)
msgbox x

Ltrim Function

It removes spaces from left side of a string that is starting from left and returns the String.

Example:

Dim val
val=" VB Script"
x=LTrim(val)
msgbox x
x=Len(x)
msgbox x
val="100 "
x=LTrim(val)
msgbox x
x=Len(x)
msgbox x
val=" 2#$%^ "
x=LTrim(val)
msgbox x
x=Len(x)
msgbox x
val=" VB Script "
x=LTrim(val)
msgbox x
x=Len(x)
msgbox x
val= 100 
x=LTrim(val)
msgbox x
x=Len(x)
msgbox x

Rtrim Function

It removes spaces from right side of a string that is starting from end and returns the String.

Example:

Dim val
val="VB Script "
x=RTrim(val)
msgbox x
x=Len(x)
msgbox x
val=" 100 "
x=RTrim(val)
msgbox x
x=Len(x)
msgbox x
val=" 2#$%^ "
x=RTrim(val)
msgbox x
x=Len(x)
msgbox x
val=" VB Script "
x=RTrim(val)
msgbox x
x=Len(x)
msgbox x
val= 100 
x=RTrim(val)
msgbox x
x=Len(x)
msgbox x

Split Function

Returns a zero-based, one-dimensional array containing a specified number of sub strings.

Example:

Dim a,b,x
b="VB Script is a Powerful scripting Language"
a=Split(b," ")
x=IsArray(b)
msgbox x 'Output: False
x=IsArray(a)
msgbox x 
'Output: True
msgbox a(6) 
'Output: Language
b="VB,Script,is,a,Powerful,scripting,Language"
a=Split(b,",")
msgbox a(5) 
'Output: Scripting
b="VB Script is a Powerful scripting Language"
a=Split(b)
msgbox a(5) 
'Output: Scripting
b="[email protected]@[email protected]@[email protected]@Language"
a=Split(b,"@")
msgbox a(5)
 'Output: Scripting
"VBScriptisaPowerfulscriptingLanguage"
a=Split(b)
msgbox a(5)
 'Output: Error

CInt Function

Returns an expression that has been converted to a Variant of subtype Integer.

Example:

Dim num
num=123.45
myInt=CInt(num)
msgbox MyInt

Day Function

Day function returns a number between 1-31 from a Date expression.


Ex1) Dim myday
myday=Day("17,December,2009")
msgbox myday

Ex2) Dim myday
mydate=date
myday=Day(Mydate)
msgbox myday

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

Join Function

Returns a string created by joining a number of substrings contained in an array.

Example:

Dim mystring, myarray(3)
myarray(0)="Animesh"
myarray(1)=" "
myarray(2)="Chatterjee"
mystring=Join(MyArray)
msgbox mystring

Eval Function

Evaluates an expression and returns the result.


msgbox Eval(CInt(3456.789))
output-3456

Timer Function

Returns the number of seconds that have elapsed since 12:00 AM (midnight).

Example:

msgbox Timer()

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)

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")

Int Function

Int function returns an Integer portion of a given number.

Example:


msgbox Int(56.783227)
output-56

IsEmpty Function

IsEmpty function returns true or false if the variable is not initialized.

Example:


Dim myVar
msgbox IsEmpty(myVar)
output-True
myVar=10
msgbox IsEmpty(myVar)
output-False

Atn Function

Atn function returns an arc tangent(ATAN) value of the argument.

Example:


msgbox ATN(1)

CBool Function

CBool function returns a boolean value of a given expression.On the off chance that expression is zero, at that point returns false, generally returns true . On the other hand if expression can’t be deciphered as a numeric esteem, at that point a runtime error happens.
Syntax:

CBool(expression As Variant) As Boolean

Example:

Dim X, Y, TestCheck
X = 5
Y = 5
TestCheck = CBool(X = Y)  'Check contains true
X = 0
Check = CBool(X)  'Check contains false

CByte Function

CByte function returns a byte value of a given expression.This function is used to convert to a particular datatype instead of default datatype.CByte will force to change the resultant datatype from single-precision, double-precision, or integer arithmetic.Just in case if the expression does not fit into valid byte range, it will throw an error.

Syntax:

CByte(expression As Variant) As Byte
output=CByte(expression)

Example:

Dim nMyDouble, nMyByte
nMyDouble = 123.789
nMyByte = CByte(nMyDouble)  
'nMyByte contains 124

CCur Function

Returns the currency value of a given expression.It can also convert any string or number to sub type currency.

Syntax:
CCur(string As String) As Currency
Calling:
n = CCur(string)
m=CCur(number)

Example:

msgbox CCur("123")
'output 123
msgbox CCur(123)
'output 123

 

VBScript – FormatDateTime a special note

This write-up will operate via some illustrations on how to use VBScript to adjust a day and/or time into diverse formats.

The operate that can make this much easier is termed FormatDateTime.

Remember to Observe:

The structure of the day and time can differ from one computer to the next since it is exhibited as for every configurations in the “Regional and Language Solutions” in the “Regulate Panel”.

Syntax:

FormatDateTime(Date,Structure)

Day:

Any valid date expression

Format:

vbGeneralDate -OR- : Small day and prolonged time

vbLongDate -OR- 1 : Prolonged date

vbShortDate -OR- 2 : Brief date

vbLongTime -OR- 3 : Extended time

vbShortTime -OR- 4 : Short time (24-hour structure)

-OR-

Sample return “2018/09/12 10:10:28 PM”

-OR-

Sample return “12 September 2018”

-OR-

Sample return “2018/09/12”

-OR-

Sample return “10:14:58 PM”

-OR-

Sample return “12 September 2018”

You should Note:

If you switch Now() with a set date without the need of a time, in each individual scenario in which ordinarily a time is revealed, it will be omitted (display only a date) and where by only a time is shown (eg. vbShortTime) it will return “00:00”.

Sample return “00:00”

 

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 15
  • 23
  • 18
  • 18
  •  
  •  
  •  
  •  
  •  
  •  
    74
    Shares

1 COMMENT

  1. Warm Greetings,
    Mr. Animesh, would kindly shed some light on the topic of Regression Testing. Some of the QA forums are quite confusing. People have different experiences and they have their own point of view and styles regarding how they approach Regression Testing. Some says that Regression Testing is conducted when there is a new release or build joined the existing application. Some people also include that Regression testing is needed after bug is fixed and sent back to the QA team to recheck. So which is the right definition? and could you also give me a scnerio based example so i will have a better understanding of it. Thanks for listening to me and providing me with your helpful views.

LEAVE A REPLY

Please enter your comment!
Please enter your name here