Wednesday, November 18, 2009

VB Script In built Functions

Command: InputBox.

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.

Syntax: InputBox(“Enter your name”)

Command: MsgBox.

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.

Syntax: MsgBox(“Hello World”)

String Functions:

StrComp: Returns a value indicating the result of a string comparison.

Usage: A=Strcmp(“Hello”,”Hello”)

A will have value 0 which means true.

InStr: Returns the position of the first occurrence of one string within another

Usage: val1="welcome to India"

val2="India"

val=InStr(1,val1,val2)

val will have value 12 . This means that the position of the word India in val1 is 12.

Split: Returns a zero-based, one-dimensional

array containing a specified number of substrings with respect to delimiter.

Usage:

Val=”appleXballXcatXdog”

Sval=Split(val,”X”,-1)

Now Sval(0) will have apple

Sval(1)=ball

Sval(2)=cat.

That is Split command will split the string based upon the delimiter specified.

Date and Time Functions:

Now: Returns the current date and time according to the setting of your computer's system date and time.

Usage:

Dim MyVar

MyVar = Now ' MyVar contains the current date and time.

DateAddf: Returns the number of intervals between two dates

Usage:

DiffADate = "Days from today: " & DateDiff("d", Now,"2/7/2008" )

MsgBox DiffADate

DiffADate will have the no of days between today and "2/7/2008"

DateAdd: Returns a date to which a specified time interval has been added.

Usage:

NewDate = DateAdd("m", 1, "31-Jan-95")

The NewDate will be “28-Feb-95”. One month latter than “31-Jan-95”

Day(now): This will return todays day alone. Like 21, 15 or 12

Hour(now): This will retun the current hour alone.

No comments:

Post a Comment

I welcome your comment, will respond and post it at the earliest:)