VBScript V1.0

May 15, 2018 | Author: k.vishnu vardhan | Category: Parameter (Computer Programming), Computer Programming, Software Engineering, Notation, Computing
Share Embed Donate


Short Description

Download VBScript V1.0...

Description

VB Script Standard Functions VB Script

1. What is VBScript?..................................................... .................................. ......................................... .............. ............. ......4 2. How does it Work?..................................................... ..................................................... 4. 3. Date/Time Functions.................................................... ................................................. .................................................... ...4 4. Conversion Functions................................................... ...................................................................................... .......................................... .............. ......... ..5 5. Format Functions........................................................ ........................................ ............................................... ............. ......5 6. Math Functions................................................... .............................................................................................. .................................................. ............... ........... ...5 7. Array Array Functions...................................................... ............................... ...................................... .............. .............. ............ .....6 8. String Functions Func tions............................................... ....................................................................................................... ........................................................ ....... ........6. 9. Other Functions...................................................... ............................... ...................................... .............. .............. ............ .....7 10. Date / Time Functions Syntax with Example .......................................... .................................................. ............... .............. .......8 10.1 Write Write text : How to write text on a page................................................ ....................................................... .............. .......... ...8 10.2 CDA CDATE TE................................................. ......................................................................................................... ........................................................ ............8 10.3 Date .........................................................................................................................9 10.4 DateAdd................................................. .................................................................................................. ........................................................ .............. ......... ..9 10.5 DateDiff................................................. ......................................................................................... ............................................... .............. .............. .......... ...10 10 10.6 DatePart ........................................................ ..................................................... .....11 11 10.7 DateSerial ....................................................... .................................................... ....12 12 10.8 DateV DateValue alue............................................... .................................................................................................... ..................................................... ....... ........... ....13 13 10.9 Day................................................ ....................................................................................................... ....................................................... .............. .................. ....13 13 10.10 FormatDateTime................................................... ................................................................................... ....................................... .............. ........14 1 .4 10.11 Hour................................................. ........................................................................................... ................................................. .............. .............. ............ .....14 14 10.12 IsDate.................................................... ............................................... ...................................................... .............. ......... ..14 14 10.13 Minute.................................................... ................................................. ........................................................ ............. ......15 15 10.14 Month................................................... ......................................................................................................... ...................................................... ....... .......... ...15 15 10.15 MonthName........................................................ ............................ .................................... ............... ............. ......16 16 10.16 Now ...................................................... ........................................................ ........16 16 10.17 Second .................................................. .......................................................................................................... ........................................................ ........16 16 10.18 Time................................................. ............................................................................................... ..................................................... .............. .............. ........17 1. 7 10.19 Timer...................................................... ................................................. ........................................................ ............. ......17 17 10.20 TimeSerial....................................................... ......................................... ................................................ ............ .....17 17 10.21 TimeValue TimeValue............................................... ......................................................................................... .................................................. ............... ........... ....18 18 10.22 Weekday................................................. ...................................................................................................... ..................................................... ....... ......... ..18 18 10.23 WeekdayName WeekdayName...................................................... ............................ ................................... .............. ............ .....19 19 10.24 Year Year.................................................. ................................................................................................ ..................................................... .............. .............. ........19 1. 9 11. Conversion Functions Syntax with Example..................................................... ....... .......... ...20 20 11.1 Asc...................................................... ........................................................ ............20 20 11.2 CBool...................................................... ........................................... .................................................. .............. ............. ......20 20 11.3 CByte CByte....................................................... .................................... ........................................... ............... ............... ........... ....20 20 11.4 CCur...................................................... .................................................. ......................................................... ............... ........21 21 11.5 CDate....................................................... .................................... ........................................... ............... ............... ........... ....21 21 11.6 CDbl...................................................... .................................................. ......................................................... ............... ........22 22 11.7 Chr...................................................... ........................................................ ............22 22 11.8 CInt................................................... ........................................................................................................... ........................................................ ..............23 23 11.9 CLng ................................................. ......................................................................................................... ........................................................ ..............23 23 11.10 CSng................................................... ........................................................................................................... ........................................................ ........ .......... ..23 23 Page 1 of 69

VB Script Standard Functions 11.11 11.1 1 CStr............................................... .......................................................................................... .................................................. ............... ............... ............. ......24 24 11.12 Hex...................................................... .................................................. ......................................................... ............... ........24 24 11.13 Oct..................................................... ........................................................ ....... ........... ....25 25 12. Format Functions Syntax with Example.................................................. ...................................................................... ....................26 26 12.1 FormatCurrency................................................ ...................................................................................... ............................................. .............. ........26 2 .6 12.2 FormatDateTime..................................................... ................................ ....................................... .............. ........27 2 .7 12.3 FormatNumber................................................ .............................................................................................. ..................................................... ......... ..28 28 12.4 FormatPercent................................................... ............................................................................................ ................................................ ............ .....29 29 13. Math Functions Func tions Syntax with Example ....................................................... ..................30 30 13.1 Abs..................................................... .............................................. ..................................................... .............. .............. ........30 3. 0 13.2 Atn................................................. ......................................................................................................... ........................................................ ............... ................. ..30 30 13.3 Cos..................................................... ............................................. .................................................... .............. .............. ......... ..30 30 13.4. Exp................................................... ....................................................................................................... .................................................... ....... .............. .......... ...31 31 13.5. Hex........................................................ ...................................................... ....... .......... ...31 31 13.6 Int...................................................... .................................................... ....... .............. .......... ...32 32 13.7 Fix.................................................... .................................................. ......................................................... .............. ............. ......33 33 13.8 Log.................................................... .................................................... ....... .............. .......... ...33 33 13.9 Oct................................................. ......................................................................................................... ........................................................ ............... ................. ..33 33 13.10 Rnd....................................................... ...................................................... ....... .......... ...34 34 13.11 Sgn................................................... ............................................................................................. ................................................. .............. .............. ............ .....35 35 13.12 Sin.................................................. .................................................................................................... ......................................................... .............. ............. ......36 36 13.13 Sqr................................................. ........................................................................................................ ....................................................... ......... ................ .......36 36 13.14 Tan.................................................... ........................................................ ............36 36 14. Array Functions Syntax with Example ................................................ ............................................................... ...................... ......... ..37 37 14.1 Array .....................................................................................................................37 37 14.2 Filter....................................................... ...................................................... ....... .......... ...37 37 14.3 Is Array............................................... ....................................................................................................... ........................................................ ............38 38 14.4 Join................................................ ....................................................................................................... ....................................................... .............. .................. ....39 39 14.5 LBound................................................ ......................................................................................... ................................................ .............. .............. ........... ....39 39 14.6 Split................................................. ........................................................................................................ ....................................................... ......... ................ .......40 40 14.7 UBound.................................................... ................................................. ........................................................ ............. ......41 41 15. String Functions Syntax with Example.............................................. ..................................................... .............. .............. ........... ....41 41 15.1 InStr.................................................... ........................................................ ............41 41 15.2 In Str Rev................................................... ............................................................................................... ................................................... .............. ......... ..42 42 15.3 LCase................................................. .............................................................................................. .................................................... .............. .............. ......... ..43 43 15.4 Left................................................ ....................................................................................................... ....................................................... .............. .................. ....44 44 15.5 Len..................................................... ............................................. .................................................... .............. .............. ......... ..44 44 15.6 Ltrim.................................................... ......................................... ................................................ .............. .............. ........... ....45 45 15.7 RTrim RTrim...................................................... .......................................... .................................................. ............... ............. ......45 45 15.8 Trim............................................... ....................................................................................................... ........................................................ ............... ................. ..45 45 15.9 Mid................................................ ....................................................................................................... ....................................................... .............. .................. ....46 46 15.10 Replace ............................................... ....................................................................................................... ........................................................ ..........46 46 15.11 Right................................................... ........................................................................................................... ........................................................ ........ .......... ..47 47 15.12 Space...................................................... ................................................. ........................................................ ............. ......47 47 15.13 Str Comp.................................................. .............................................................................................. ................................................... .............. ......... ..48 48 15.14 String .................................................... ........................................................ ........48 48 15.15 Str Reverce .................................................. .................................................................................................... ......................................................... .......49 49 15.16 Ucase.................................................. .......................................................................................................... ........................................................ ......... ..........49 4. 9 16. Other Functions Syntax with Example ................................................ ............................................................... ...................... ......... ..49 49 Page 2 of 69

VB Script Standard Functions 16.1 CreateObject........................................................ ........................... .................................. .............. .............. ......... ..49 49 16.2 Eval.................................................. .................................................................................................... ......................................................... .............. ............. ......50 50 16.3 GetLocale............................................... .................................................................................................... ..................................................... ....... ........... ....50 50 16.4 Get Object ....................................................... ...................................... ............................................. .............. ........51 5. 1 16.5 GetRef .................................................................................................................51 51 16.6 InputBox....................................................... ................................. ........................................ .............. .............. .......... ...51 51 16.7 IsEmpty.................................................... ................................................. ........................................................ ............. ......52 52 16.8 IsNull.................................................. .......................................................................................................... ........................................................ ............53 53 16.9 IsNumaeric...................................................... .............................................. ..................................................... ......... ..53 53 16.10 IsObject.................................................. ................................................................................................... ........................................................ ............. ......54 54 16.11 LoadPicture.................................................. .......................................................................................... ............................................... .............. ......... ..54 54 16.12 MsgBox ................................................ ........................................................................................................ ........................................................ ........55 55 16.13 RGB ....................................................................................................................56 56 16.14 Round ................................................... ......................................................................................................... ...................................................... ....... .......... ...57 57 16.15 Script Engine................................................ .................................................................................................... .................................................... ....57 57 16.16 ScriptEngineBuildV ScriptEngineBuildVersion ersion...................................................... ..............................58 58 16.17 ScriptEngineMajorVersion ScriptEngineMajorVersion Function......................................... ................................................ ............... ............... ........... ....58 58 16.18 ScriptEngineMinorVersion ScriptEngineMinorVersion Function ............................................... ...................................................... .............. ............. ......58 58 16.19 SetLocate.................................................... ....................................................... ...58 58 16.20 TypeName....................................................... ..................................... ............................................ .............. ......... ..59 59 16.21 VarT arType ype................................................. ............................................................................................... ..................................................... .............. .......... ...60 60 17. For Loop Syntax................................................. ...................................................................................... ............................................ .............. ............. ......61 61 Repeats a block of statements while a condition is True or until a condition becomes True.................................................................................................................................... True. ...................................................................................................................................62 62 18. Do While Syntax...................................................... ................................................ .................................................... ....62 62 19. While Statement Syntax .................................................. ............................................................................................... .............................................63 63 20. If Then Else Syntax.................................................. ..................................................................................................... ....................................................64 6. 4 21.Sub Routine Syntax...................................................... ........................... .................................. .............. .............. .......66 66 .......................................................................................................................................... 67 22.Function Syntax............................................... .............................................................................................. ...................................................... .............. .......67 67

Page 3 of 69

VB Script Standard Functions 1. What is VBScript? • • •

VBScript is a scripting language A scripting language is a lightweight programming language VBScript is a light version of Microsoft's programming language Visual Basic

2. How does it Work?

When a VBScript is inserted into a HTML document, the Internet browser will read the HTML and interpret the VBScript. The VBScript can be executed immediately, immediately, or at a later event. 3. Date/Time Functions Function CDate

Description Converts a valid date and time expression to the variant of  subtype Date

Date DateAdd

Returns the current system date Returns a date to which a specified time interval has been added Returns the number of intervals between two dates Returns the specified part of a given date Returns the date for a specified year, month, and day Returns a date Returns a number that represents the day da y of the month (between 1 and 31, inclusive) Returns an expression formatted as a date or time Returns a number that represents the hour of the day (between 0 and 23, inclusive) Returns a Boolean value that indicates if the evaluated expression can be converted to a date Returns a number that represents the minute of the hour  (between 0 and 59, inclusive) Returns a number that represents the month of o f the year  (between 1 and 12, inclusive) Returns the name of a specified month Returns the current system date and time Returns a number that represents the second of the minute (between 0 and 59, inclusive) Returns the current system time Returns the number of seconds since 12:00 AM Returns the time for a specific hour, minute, and second Returns a time Returns a number that represents the day da y of the week 

DateDiff  DatePart DateSerial DateValue Day FormatDateTime Hour  IsDate Minute Month MonthName  Now Second Time Timer  TimeSerial TimeValue Weekday

Page 4 of 69

VB Script Standard Functions (between 1 and 7, inclusive) WeekdayName Returns the weekday name of a specified day of the week  Year  Returns a number that represents the year  Top

4. Conversion Functions Function Asc

Description Converts the first letter in a string to ANSI code

CBool CByte CCur  CDate

Converts an expression to a variant of o f subtype Boolean Converts an expression to a variant of o f subtype Byte Converts an expression to a variant of o f subtype Currency Converts a valid date and time expression to the variant of  subtype Date Converts an expression to a variant of o f subtype Double Converts the specified ANSI code to a character  Converts an expression to a variant of o f subtype Integer  Converts an expression to a variant of o f subtype Long Converts an expression to a variant of o f subtype Single Converts an expression to a variant of o f subtype String Returns the hexadecimal value of a specified number  Returns the octal value of a specified number 

CDbl Chr  CInt CLng CSng CStr  Hex Oct

Top

5. Format Functions Function FormatCurrency

Description Returns an expression formatted as a currency value

FormatDateTime FormatNumber  FormatPercent

Returns an expression formatted as a date or time Returns an expression formatted as a number  Returns an expression formatted as a percentage Top

6. Math Functions Function

Description

Abs Atn Cos Exp Hex Int Fix Log

Returns the absolute value of a specified number  Returns the arctangent of a specified number  Returns the cosine of a specified number nu mber (angle) Returns e raised to a power  Returns the hexadecimal value of a specified number  Returns the integer part of a specified number  n umber  Returns the integer part of a specified number  n umber  Returns the natural logarithm of a specified number  Page 5 of 69

VB Script Standard Functions Oct Returns the octal value of a specified number  Rnd Returns a random number less than 1 but greater or equal to 0 Sgn Returns an integer that indicates the sign of a specified number  Sin Returns the sine of a specified number (angle) Sqr  Returns the square root of a specified number  n umber  Tan Returns the tangent of a specified number (angle) Top

7. Array Functions Function

Description

Array Filter 

Returns a variant containing an array Returns a zero-based array that contains a subset of a string array based on a filter criteria Returns a Boolean value that indicates whether a specified variable is an array Returns a string that consists of a number of substrings in an array Returns the smallest subscript for the indicated dimension of  an array Returns a zero-based, one-dimensional array that contains a specified number of substrings Returns the largest subscript for the indicated dimension of  an array

IsArray Join LBound Split UBound

Top

8. String Functions Function InStr 

Description Returns the position of the first occurrence of one string within another. The search begins at the first character of the string

InStrRev

Returns the position of the first occurrence of one string within another. The search begins at the last character of the string Converts a specified string to lowercase Returns a specified number of characters from the left side of  a string Returns the number of characters in a string Removes spaces on the left side of a string Removes spaces on the right side of a string Removes spaces on both the left and the right side of a string Returns a specified number of characters from a string

LCase Left Len LTrim RTrim Trim Mid

Page 6 of 69

VB Script Standard Functions Replace Replaces a specified part of a string with another string a specified number of times Right Returns a specified number of characters from the right side of a string Space Returns a 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 Returns a string that contains a repeating character ch aracter of a specified length StrReverse Reverses a string UCase Converts a specified string to uppercase Top

9. Other Functions Function CreateObject

Description Creates an object of a specified type

Eval GetLocale GetObject GetRef 

Evaluates an expression and returns the result Returns the current locale ID Returns a reference to an automation object from a file Allows you to connect a VBScript procedure to a DHTML event on your pages InputBox Displays a dialog box, where the user can write some input and/or click on a button, and returns the contents IsEmpty Returns a Boolean value that indicates whether a specified variable has been initialized or not IsNull Returns a Boolean value that indicates whether a specified expression contains no valid data (Null) IsNumeric Returns a Boolean value that indicates whether a specified expression can be evaluated as a number  IsObject Returns a Boolean value that indicates whether the specified expression is an automation object LoadPicture Returns a picture object. o bject. Available Available only on 32-bit platforms MsgBox Displays a message box, waits for the user to click c lick a button, and returns a value that indicates which button the user  clicked RGB Returns a number that represents an RGB color c olor value Round Rounds a number  ScriptEngine Returns the scripting language in use ScriptEngineBuildVersion Returns the build version number of the scripting engine in use ScriptEngineMajorVersion Returns the major version number of the scripting engine in use ScriptEngineMinorVersion Returns the minor version number of the scripting engine in Page 7 of 69

VB Script Standard Functions use SetLocale Sets the locale ID and returns the previous locale ID TypeName Returns the subtype of a specified variable VarType Returns a value that indicates the subtype of a specified variable 10. Date / Time Functions Syntax with Example 10.1 Write text : How to write text on a page

document.write("Hello from VBScript!Written By kasi k asi Viswaandham") Viswaandham") 10.2 CDATE

The CDate function converts a valid date and time expression to the variant of subtype Date, and returns the result. Tip: Use the IsDate function to determine if date can be converted to a date or time. Note: The IsDate function uses local setting to determine if a string can be converted to a date ("January" is not a month in all languages.)

CDate(date) Parameter date

Description Required. Any valid date expression (like Date() or Now())

Example 1 d="April 22, 2001" if IsDate(d) then document.write(CDate(d)) end if  Output: 2/22/01 Example 2 d=#2/22/01# if IsDate(d) then document.write(CDate(d)) end if  Output: 2/22/01 Example 3 d="3:18:40 AM" if IsDate(d) then document.write(CDate(d)) Page 8 of 69

VB Script Standard Functions end if  Output: 3:18:40 AM 10.3 Date

The Date function returns the current system date Syntax document.write("The current system date is: ") document.write(Date) Output: The current system date is: 1/14/2002 10.4 DateAdd

The DateAdd function returns a date to which a specified time interval has been added. Syntax DateAdd(interval,number,date) Parameter interval

Description Required. The interval you want to add

Can take the following values: • • • • • • • • •

yyyy - Year  q - Quarter  m - Month y - Day of year  d - Day w - Weekday ww - Week of year  h - Hour  n - Minute

s - Second Required. The nu number of of in interval yo you wa want to to ad add. Ca Can ei either be be  positive, for dates in the future, or negative, for dates in the past Required. Variant or literal representing the date to which interval is added •

number date

Example 1 'Add one month to January 31, 2000 document.write(DateAdd("m",1,"31-Jan-00")) Output: 2/29/2000 Example 2 'Add one month to January 31, 2001 document.write(DateAdd("m",1,"31-Jan-01")) Page 9 of 69

VB Script Standard Functions Output: 2/28/2001 10.5 DateDiff 

The DateDiff function returns the number of intervals between two dates. Syntax DateDiff(interval,date1,date2[,firstdayofweek[,firstweekofyear]]) Parameter

Description

interv erval

Requir uired. The interval val yo you wa want to to us use to to cal calccula ulate th the di difference nces  between date1 and date2 Can take the following values: • • • • • • • • •

yyyy - Year  q - Quarter  m - Month y - Day of year  d - Day w - Weekday ww - Week of year  h - Hour  n - Minute

s - Second Requ Requir ired ed.. Dat Datee expr expres essi sion ons. s. Two date datess you you wan wantt to to use use in the the calculation Option Optional. al. Specif Specifies ies the day of the week. week. •

date date1, 1,da date te2 2 firstd firstday ayofw ofweek eek

Can take the following values: •

• • • • • •

0 = vbUseSystemDayOfW vbUseS ystemDayOfWeek eek - Use National Language Support S upport (NLS) API setting 1 = vbSunday - Sunday (default) 2 = vbMonday - Monday 3 = vbTuesday - Tuesday 4 = vbWednesday - Wednesday 5 = vbThursday - Thursday 6 = vbFriday - Friday

7 = vbSaturday - Saturday firstweeko firstweekofyear fyear Optional. Optional. Specifi Specifies es the the first first week of of the the year year.. •

Can take the following values: Page 10 of 69

VB Script Standard Functions •







0 = vbUseSystem - Use National Language Support (NLS) API setting 1 = vbFirstJan1 - Start with the week in which January 1 occurs (default) 2 = vbFirstFourDays - Start with the week that has at least four  days in the new year  3 = vbFirstFullWeek vbFirstFullWeek - Start with the first full week of the new year 

Example 1 document.write(Date & "") document.write(DateDiff("m",Date,"12/31/2002") & "") document.write(DateDiff("d",Date,"12/31/2002") & "") document.write(DateDiff("n",Date,"12/31/2002")) Output: 1/14/2002 11 351 505440 10.6 DatePart

The DatePart function returns the specified part of o f a given date. Syntax DatePart(interval, date[,firstdayofweek[,firs date[,firstdayofweek[,firstweekofyear]]) tweekofyear]]) Parameter

Description

interval

Required. The interval of time to to re return. Can take the following values: • • • • • • • • •

yyyy - Year  q - Quarter  m - Month y - Day of year  d - Day w - Weekday ww - Week of year  h - Hour  n - Minute

s - Second Required. Date expression to evaluate Option Optional. al. Specif Specifies ies the day of the week. week. •

date firstd firstday ayofw ofweek eek

Page 11 of 69

VB Script Standard Functions Can take the following values: •

• • • • • •

0 = vbUseSystemDayOfW vbUseS ystemDayOfWeek eek - Use National Language Support S upport (NLS) API setting 1 = vbSunday - Sunday (default) 2 = vbMonday - Monday 3 = vbTuesday - Tuesday 4 = vbWednesday - Wednesday 5 = vbThursday - Thursday 6 = vbFriday - Friday

7 = vbSaturday - Saturday firstweeko firstweekofyear fyear Optional. Optional. Specifi Specifies es the the first first week of of the the year year.. •

Can take the following values: •







0 = vbUseSystem - Use National Language Support (NLS) API setting 1 = vbFirstJan1 - Start with the week in which January 1 occurs (default) 2 = vbFirstFourDays - Start with the week that has at least four  days in the new year  3 = vbFirstFullWeek vbFirstFullWeek - Start with the first full week of the new year 

Example 1 document.write(Date & "") document.write(DatePart("d",Date)) Output: 1/14/2002 14 10.7 DateSerial

The DateSerial function returns a Variant Variant of subtype Date for a specified year, month, and day. Syntax DateSerial(year,month,day) Parameter

Description

year

Required. A number between 100 and 9999, or a numeric expression. Values between 0 and 99 are interpreted as the years 1900–1999. 1900–1 999. For all other year arguments, use a complete four-digit year  Required. Any numeric ex expression

month

Page 12 of 69

VB Script Standard Functions day Required. Any numeric expression Example 1 document.write(DateSerial(1996,2,3) & "") document.write(DateSerial(1990-20,9-2,1-1)) Output: 2/3/1996 6/30/1970 10.8 DateValue DateValue

The DateValue DateValue function returns a Variant Variant of subtype Date. Note: If the year part of date is omitted this function will use the current year from the computer's system date. Note: If the date parameter includes time information it will not be returned. However, if  date includes invalid time information, a run-time error will occur.

Syntax DateValue(date) Parameter

Description

date

Required. A date fr from January 1, 100 through De December 31, 9999 or or   any expression that can represent a date, a time, or both a date and time

Example 1 document.write(DateValue("31-Jan-02") document.write(DateValue("31-Jan-02") & "") document.write(DateValue("31-Jan") document.write(DateValue("31-Jan") & "") document.write(DateValue("31-Jan-02 document.write(DateValue("31-Jan-02 2:39:49 AM")) Output: 1/31/2002 1/31/2002 1/31/2002 10.9 Day

The Day function returns a number between 1 and 31 that represents the day of the month. Syntax Day(date) Parameter date

Description Required. Any expression that can represent a date

Example 1 document.write(Date & "") document.write(Day(Date)) Page 13 of 69

VB Script Standard Functions Output: 1/14/2002 14 10.10 FormatDateTime

The FormatDateTime function formats and returns a valid date or time expression. Syntax FormatDateTime(date,format) Parameter date

Description Required. Any valid date expression (like Date() or Now())

format Optional. A Format value that specifies the date/time format to use Example 1 document.write("The current date is: ") document.write(FormatDateTime(Date())) Output: The current date is: 2/22/2001 10.11 Hour

The Hour function returns a number between 0 and 23 that represents the hour of the day. Syntax Hour(time) Parameter time

Description Required. Any expression that can represent a time

Example 1 document.write(Now & "") document.write(Hour(Now)) Output: 1/15/2002 10:07:47 AM 10 10.12 IsDate

The IsDate function returns a Boolean value that indicates if the evaluated expression can  be converted to a date. It returns True if the expression is a date or can be converted to a date; otherwise, it returns False. Note: The IsDate function uses local setting to determine if a string can be converted to a date ("January" is not a month in all languages.)

Syntax Page 14 of 69

VB Script Standard Functions IsDate(expression) Parameter expr xpression

Description Requir uired. The exp express ession to to be be eva evalluat uated

Example 1 document.write(IsDate("April 22, 1947") & "") document.write(IsDate(#11/11/01#) document.write(IsDate(#1 1/11/01#) & " 0 Example 1 document.write(Log(38.256783227)) Output: 3.64432088381777 13.9 Oct

Page 33 of 69

VB Script Standard Functions The Oct function returns a string that represents the octal value of a specified number nu mber.. Note: If number is not already a whole number, it is rounded to the nearest whole number   before being evaluated.

Syntax Oct(number) Parameter number

Description Required. Any valid ex expression

If number is: • •



 Null - then the Oct function returns Null. Empty - then the Oct function returns zero (0). Any other number - then the Oct function returns up to 11 octal characters.

Example 1 document.write(Oct(3) & "") document.write(Oct(5) & "") document.write(Oct(9) & "") document.write(Oct(10) & "") document.write(Oct(11) & "") document.write(Oct(12) & "") document.write(Oct(400) & "") document.write(Oct(459) & "") document.write(Oct(460)) Output: 3 5 11 12 13 14 620 713 714 13.10 Rnd

The Rnd function returns a random number. The number is always less than 1 but greater  or equal to 0. Syntax Rnd[(number)]

Page 34 of 69

VB Script Standard Functions Parameter Description number Optional. A valid numeric expression If number is: 0 - Rnd returns the next random number in the sequence =0 - Rnd returns the most recently generated number 

• • •



 Not supplied - Rnd returns the next random number in the sequence

Example 1 document.write(Rnd) Output: 0.7055475 Example 2 'If you refresh the page, 'using the code in example 1, 'the SAME random number will show over ove r and over. 'Use the Randomize statement generate a new random number  'each time the page is reloaded! Randomize document.write(Rnd) Output: 0.4758112 13.11 Sgn

The Sgn function returns an integer that indicates the sign of a specified number. Syntax Sgn(number) Parameter number

Description Required. A valid numeric expression

If number is:



>0 - Sgn returns 1 =0 - Sgn returns 0



= 0

Example 1 document.write(Sqr(9)) Output: 3 13.14 Tan

The Tan function returns the tangent of a specified number (angle). Syntax Tan(number) Parameter

Description

num number ber Requ Requiired. red. A vali valid d num numeri eric expr expres esssion ion that that expr expres essses an angl anglee in radi radian anss Example 1 document.write(Tan(40)) Page 36 of 69

VB Script Standard Functions Output: -1.1172149309239

14. Array Functions Syntax with Example 14.1 Array

The Array function returns a variant containing c ontaining an array. Note: The first element in the array is zero.

Syntax Array(arglist) Parameter

Description

argli glist

Requir uired. A list (separ parated by commas) of values that hat is the eellements in the array

Example 1 dim a a=Array(5,10,15,20) document.write(a(3)) Output: 20 14.2 Filter

The Filter function returns a zero-based array that contains a subset of a string array  based on a filter criteria. Note: If no matches of the value parameter are found, the Filter function will return an empty array.

array, an error  Note: If the parameter inputstrings is Null or is NOT a one-dimensional array, will occur. Syntax Filter(inputstrings,value[,include[,compare]]) Parameter inpu inputs tstr trin ings gs

Description Requi Require red. d. A oneone-di dime mens nsio iona nall arr array ay of stri strings ngs to be sear searche ched d

value incl includ udee

Required. The string to search for   Opti Option onal al.. A Bool Boolea ean n valu valuee that that indi indica cate tess whet whethe herr to ret return urn the subs ubstring ringss that include or exclude value. True returns the subset of the array that contains value as a substring. False returns the subset of the array that does not contain value as a substring. Default is True. Page 37 of 69

VB Script Standard Functions compare Optional. Sp Specifies th the st string co comparison to to us use. Can have one of the following values: •

0 = vbBinaryCompare - Perform a binary comparison co mparison



1 = vbTextCompare - Perform a textual comparison

Example 1 dim a(5),b a(0)="Saturday" a(1)="Sunday" a(2)="Monday" a(3)="Tuesday" a(4)="Wednesday"  b=Filter(a,"n") document.write(b(0) & "") document.write(b(1) & "") document.write(b(2)) Output: Sunday Monday Wednesday Example 2 dim a(5),b a(0)="Saturday" a(1)="Sunday" a(2)="Monday" a(3)="Tuesday" a(4)="Wednesday"  b=Filter(a,"n",false) document.write(b(0) & "") document.write(b(1) & "") document.write(b(2)) Output: Saturday Tuesday 14.3 Is Array

The IsArray function returns a Boolean value that indicates whether a specified variable is an array. If the variable is an a n array, array, it returns True, otherwise, it returns False. Syntax IsArray(variable)

Page 38 of 69

VB Script Standard Functions Parameter Description variable Required. Any variable Example 1 dim a(5) a(0)="Saturday" a(1)="Sunday" a(2)="Monday" a(3)="Tuesday" a(4)="Wednesday" document.write(IsArray(a)) Output: True 14.4 Join

The Join function returns a string that consists con sists of a number of substrings in an array. Syntax Join(list[,delimiter]) Parameter list

Description Required. A one-dimensional array that contains the substrings to be  joined

deli delimi mite terr

Opti Option onal al.. Th Thee char charac acte ter( r(s) s) used used to sepa separa rate te the the subs substr trin ings gs in the the ret retur urne ned d string. Default is the space character 

Example 1 dim a(5),b a(0)="Saturday" a(1)="Sunday" a(2)="Monday" a(3)="Tuesday" a(4)="Wednesday"  b=Filter(a,"n") document.write(join(b)) Output: Sunday Monday Monda y Wednesday Wednesday 14.5 LBound

The LBound function returns the smallest subscript for the indicated dimension of an array. Note: The LBound for any dimension is ALWAYS 0. Tip: Use the LBound function with the UBound function to determine the size of an array.

Page 39 of 69

VB Script Standard Functions Syntax LBound(arrayname[,dimension]) Parameter arrayna aynam me

Description Requir uired. The nam name of the array variable ble

dime dimens nsio ion n

Opti Option onal al.. Whi Which ch dime dimens nsio ion' n'ss low lower er boun bound d to to ret retur urn. n. 1 = fir first st dime dimens nsio ion, n, 2 = second dimension, and so on. Default is 1

Example 1 dim a(10) a(0)="Saturday" a(1)="Sunday" a(2)="Monday" a(3)="Tuesday" a(4)="Wednesday" a(5)="Thursday" document.write(UBound(a)) document.write("") document.write(LBound(a)) Output: 10 0 14.6 Split

The Split function returns a zero-based, one-dimensional array that contains a specified number of substrings. Syntax Split(expression[,delimiter[,count[,compare]]]) Parameter expr expres essi sion on

Description Requ Requir ired ed.. A stri string ng exp expre ress ssio ion n that that con conta tain inss subs substr trin ings gs and and del delim imit iter erss

deli delimi mite terr

Opti Option onal al.. A stri string ng char charac acte terr use used d to to ide ident ntif ify y subs substr trin ing g lim limit its. s. Defa Defaul ultt is is the space character  Optional. The nu number of su substrings to be be re returned. -1 -1 in indicates th that al all substrings are returned Optional. Sp Specifies th the st string co comparison to to us use.

count compare

Can have one of the following values: •

0 = vbBinaryCompare - Perform a binary comparison co mparison



1 = vbTextCompare - Perform a textual comparison

Example 1 dim txt,a Page 40 of 69

VB Script Standard Functions txt="Hello World!" a=Split(txt) document.write(a(0) & "") document.write(a(1)) Output: Hello World! 14.7 UBound

The UBound function returns the largest subscript for the indicated dimension of an array. Tip: Use the UBound function with the LBound function to determine the size of an array.

Syntax UBound(arrayname[,dimension]) Parameter arrayna aynam me

Description Requir uired. The nam name of the array variable ble

dime dimens nsio ion n

Opti Option onal al.. Whi Which ch dime dimens nsio ion' n'ss upp upper er boun bound d to to ret retur urn. n. 1 = fir first st dime dimens nsio ion, n, 2 = second dimension, and so on. Default is 1

Example 1 dim a(10) a(0)="Saturday" a(1)="Sunday" a(2)="Monday" a(3)="Tuesday" a(4)="Wednesday" a(5)="Thursday" document.write(UBound(a)) document.write("") document.write(LBound(a)) Output: 10 0 15. String Functions Syntax with Example 15.1 InStr

The InStr function returns the position of the first occurrence of one string within another. The InStr function can return the following values: • •

If string1 is "" - InStr returns 0 If string1 is Null - InStr returns Null Page 41 of 69

VB Script Standard Functions If string2 is "" - InStr returns start If string2 is Null - InStr returns Null If string2 is not found - InStr returns 0 If string2 is found within string1 - InStr returns the position at which match is found If start > Len(string1) - InStr returns 0 • • • •



Tip: Also look at the InStrRev function

Syntax InStr([start,]string1,string2[,compare]) Parameter start

Description Optional. S Sp pecifies th the st starting po position fo for ea each se search. Th The se search  begins at the first character position by default. This parameter is required if compare is specified

string1 string2 comp ompare

Required. The string to be searched Required. The string ex expression to to se search for   Optiona onal. Sp Specif cifies th the st string co comparison to to us use. De Default is is 0 Can have one of the following values: •

0 = vbBinaryCompare - Perform a binary comparison co mparison



1 = vbTextCompare - Perform a textual comparison

Example 1 dim txt,pos txt="This is a beautiful day!"  pos=InStr(txt,"his") document.write(pos) Output: 2 15.2 In Str Rev

The InStrRev function returns the position of the first occurrence of one string within another. The search begins from the end of string, but the position returned counts from the beginning of the string. The InStrRev function can return the following values: • • • • •

If string1 is "" - InStrRev returns 0 If string1 is Null - InStrRev returns Null If string2 is "" - InStrRev returns start If string2 is Null - InStrRev returns Null If string2 is not found - InStrRev returns 0 Page 42 of 69

VB Script Standard Functions If string2 is found within string1 - InStrRev returns the position at which match is found If start > Len(string1) - InStrRev returns 0 •



Tip: Also look at the InStr function

Syntax InStrRev(string1,string2[,start[,compare]]) Parameter string1

Description Required. The string to be searched

string2 start

Required. The string ex expression to to se search for   Optional. S Sp pecifies th the st starting po position fo for ea each se search. Th The se search  begins at the last character position by default (-1) Optiona onal. Sp Specif cifies th the st string co comparison to to us use. De Default is is 0

comp ompare

Can have one of the following values: •

0 = vbBinaryCompare - Perform a binary comparison co mparison



1 = vbTextCompare - Perform a textual comparison

Example 1 dim txt,pos txt="This is a beautiful day!"  pos=InStrRev(txt,"his") document.write(pos) Output: 15.3 LCase

The LCase function converts a specified string to lowercase. Tip: Also look at the UCase function.

Syntax LCase(string) Parameter

Description

string Required. The string to be converted to lowercase Example 1 dim txt txt="THIS IS A BEAUTIFUL DAY!" document.write(LCase(txt)) Output: this is a beautiful day! Page 43 of 69

VB Script Standard Functions Example 2 dim txt txt="This Is a Beautiful Day!" Da y!" document.write(LCase(txt)) Output: this is a beautiful day! 15.4 Left

The Left function returns a specified number nu mber of characters from the left side of a string. Tip: Use the Len function to find the number of characters in a string. Tip: Also look at the Right function.

Syntax Left(string,length) Parameter string

Description Required. The string to return characters from

length

Requir uired. Speci ecifies how how many any characters to retu eturn. If set to 0, an empty pty string ("") is returned. If set to greater than or equa l to the length of the string, the entire string is returned

Example 1 dim txt txt="This is a beautiful day!" document.write(Left(txt,11)) Output: This is a b 15.5 Len

The Len function returns the number of characters in a string. Syntax Len(string|varname) Parameter string

Description A string expression

varname A variable name Example 1 dim txt txt="This is a beautiful day!" document.write(Len(txt)) Output: 24 Page 44 of 69

VB Script Standard Functions 15.6 Ltrim The LTrim LTrim function removes spaces on the left side of a string. Syntax LTrim(string) Parameter

Description

string Required. A string expression Example 1 dim txt txt=" This is a beautiful beautiful day! " document.write(LTrim(txt)) Output: "This is a beautiful day! "

15.7 RTrim

The RTrim RTrim function removes spaces on the right side of o f a string. Syntax RTrim(string) Parameter string

Description Required. A string expression

Example 1 dim txt txt=" This is a beautiful beautiful day! " document.write(RTrim(txt)) Output: " This is a beautiful day!" 15.8 Trim

The Trim function removes spaces on both the left and the right side of a string. Syntax Trim(string) Parameter string

Description Required. A string expression

Example 1 dim txt txt=" This is a beautiful beautiful day! " Page 45 of 69

VB Script Standard Functions document.write(Trim(txt)) Output: "This is a beautiful day!"

15.9 Mid

The Mid function returns a specified number nu mber of characters from a string. d etermine the number of characters in a string. Tip: Use the Len function to determine Syntax Mid(string,start[,length]) Parameter string

Description Required. The st string ex expression fr from which ch characters ar are re returned

start

Required. S Sp pecifies the st starting po position. If If se set to to gr greater than th the number of characters in string, it returns an empty string ("") Optional. The number of characters to return

length Example 1 dim txt txt="This is a beautiful day!" document.write(Mid(txt,1,1)) Output: T 15.10 Replace

The Replace function replaces a specified part of a string with another string a specified number of times. Syntax Replace(string,find,replacewith[,start[,count[,compare]]]) Parameter string

Description Required. The string to be searched

find repl replac acew ewit ith h start count

Required. The part of the string that will be replaced Requ Requiired. red. The The repl replac acem emen entt subs substtring ring Optional. Specifies the start position. Default is 1 Optional. S Sp pecifies the number of substitutions to perform. Default value is -1, which means make all possible substitutions Optiona onal. Sp Specif cifies th the st string co comparison to to us use. De Default is is 0

comp ompare

Can have one of the following values: Page 46 of 69

VB Script Standard Functions •

0 = vbBinaryCompare - Perform a binary comparison



1 = vbTextCompare - Perform a textual comparison

Example 1 dim txt txt="This is a beautiful day!" document.write(Replace(txt,"beautiful","horrible")) Output: This is a horrible day!

15.11 Right

The Right function returns a specified number of characters from the right side of a string. Tip: Use the Len function to find the number of characters in a string. Tip: Also look at the Left function.

Syntax Right(string,length) Parameter string

Description Required. The string to return characters from

length

Required. Specifies how many characters to return. If set to 0, an empty string ("") is returned. If set to greater than or equa l to the length of the string, the entire string is returned

Example 1 dim txt txt="This is a beautiful day!" document.write(Right(txt,11)) Output: utiful day! 15.12 Space

The Space function returns a string that consists of a specified number of spaces. Syntax Space(number) Parameter number

Description Required. The number of spaces you want in the string

Example 1 Page 47 of 69

VB Script Standard Functions dim txt txt=Space(10) document.write(txt) Output: " " 15.13 Str Comp

The StrComp function compares two strings and returns a value that represents the result of the comparison. The StrComp function can return the following values: • • • •

If string1 < string2 - StrComp returns -1 If string1 = string2 - StrComp returns 0 If string1 > string2 - StrComp returns 1 If string1 or string2 is Null - StrComp returns Null

Syntax StrComp(string1,string2[,compare]) Parameter

Description

string1 string2 compare

Required. A string expression Required. A string expression Optional. Specifies the string comparison to use. Default is 0 Can have one of the following values: •

0 = vbBinaryCompare - Perform a binary comparison



1 = vbTextCompare - Perform a textual comparison

Example 1 document.write(StrComp("VBScript","VBScript")) Output: 0 15.14 String

The String function returns a string that contains a repeating character of a specified length. Syntax String(number,character) Parameter number

Description Required. The length of the returned string

Page 48 of 69

VB Script Standard Functions character Required. The ch character th that wi will be be re repeated Example 1 document.write(String(10,"#")) Output: ########## 15.15 Str Reverce

The StrReverse function reverses a string. Syntax StrReverse(string) Parameter string

Description Required. The string to be reversed

Example 1 dim txt txt="This is a beautiful day!" document.write(StrReverse(txt)) Output: !yad lufituaeb a si sihT

15.16 Ucase

The UCase function converts a specified string to uppercase. Tip: Also look at the LCase function.

Syntax UCase(string) Parameter

Description

string Required. The string to be converted to uppercase Example 1 dim txt txt="This is a beautiful day!" document.write(UCase(txt)) Output: THIS IS A BEAUTIFUL DAY! 16. Other Functions Syntax with Example 16.1 CreateObject

The CreateObject function creates an object of a specified type. Page 49 of 69

VB Script Standard Functions Syntax CreateObject(servername.typename[,location]) Parameter serv server erna name me

Description Requ Requir ired ed.. The The nam namee of of the the app appli lica cati tion on tha thatt pro provi vide dess the the obje object ct

typename Required. The type/class of the object location Optional. Where to create the object Example 1 dim myexcel Set myexcel=CreateObject("Excel.Sheet") myexcel.Application.Visible=True ...code... myexcel.Application.Quit Set myexcel=Nothing 16.2 Eval

Eval Ev al

Eval Ev aluat uates es an expr expres essi sion on and retu return rnss the the resu result lt

16.3 GetLocale

The GetLocale function returns the current c urrent locale ID. A locale contains a set of user preference information: like language, cou ntry, ntry, region, and cultural conventions. The locale determines such things as keyboard layout, sort order, date, time, number, and currency formats. The return value can be one of the 32-bit values shown in the Locale ID chart. chart. Syntax GetLocale() Example 1 dim c c=GetLocale document.write(c) Output: 1033 

Some of the values of Locale ID Chart

Locale Description Afrikaans

Short String af

Hex Value 0x0436

Decimal Value 1 07 8

Albanian Arabic – United Arab Emirates Arabic - Bahrain Arabic - Algeria

sq ar-ae ar-bh ar-dz

0x041C 0x3801 0x3C01 0x1401

1 0 52 1 4 33 7 1 5 36 1 5 12 1 Page 50 of 69

VB Script Standard Functions 16.4 Get Object

The GetObject function returns a reference to an automation object from a file. Syntax GetObject([pathname][,class]) Parameter

Description

 pathname

Optional. The full path and name of the file that contains the automation object. If this parameter is omitted, the class parameter is required Optional. The class of the automation object. This parameter uses this syntax: appname.objectype

class 16.5 GetRef 

The GetRef function allows you to connect a VBScript procedure to a DHTML event on your pages. Syntax Set object.event=GetRef(procname) Parameter object

event  procname

Description Required. The name of a DHTML object with which DHTML event is associated Required. The name of a DHTML event to which the function is to be  bound

Required. The name of a Sub or Function procedure to be associated with the DHTML event

Example 1 Function test() dim txt txt="GetRef Test" & vbCrLf  txt=txt & "Hello World!" MsgBox txt End Function Set Window.Onload=GetRef("test") 16.6 InputBox

The InputBox function displays a dialog box, where the user can write some input and/or  click on a button. If the user clicks the OK button or presses ENTER on the keyboard, the InputBox function will return the text in the text box. If the user clicks on the Cancel  button, the function will return an empty string (""). Page 51 of 69

VB Script Standard Functions Note: A Help button is added to the dialog box when both the helpfile and the context  parameter are specified. Tip: Also look at the MsgBox function.

Syntax InputBox(prompt[,title][,default][,xpos][,ypos][,helpfile,context]) Parameter prompt

Description Required. The message to show in the dialog box. Maximum length is 1024 characters. You can separate the lines using a carriage return character (Chr(13)), a linefeed character (Chr(10)), or carriage return–  linefeed character combination (Chr(13) & Chr(10)) between each line

title default xpos

Optional. The title of the dialog box. Default is the application name Optional. A default text in the text box Optional. The horizontal distance of the left edge of the dialog box from the left edge of the screen. If omitted, the dialog box is horizontally centered Optional. The vertical distance of the upper edge of the dialog box from the top of the screen. If omitted, the dialog box is vertically positioned one-third of the way down the screen Optional. The name of a Help file to use. Must be used with the context  parameter  Optional. The Help context number to the Help topic. Must be used with the helpfile parameter 

ypos

helpfile context

Example 1 dim fname fname=InputBox("Enter your name:") MsgBox("Your name is " & fname) 16.7 IsEmpty

The IsEmpty function returns a Boolean value that indicates whether a specified variable has been initialized or not. It returns true if the variable is uninitialized; otherwise, it returns False. Syntax IsEmpty(expression) Parameter expression

Description Required. An expression (most often a variable name)

Example 1 dim x document.write(IsEmpty(x) & "") Page 52 of 69

VB Script Standard Functions x=10 document.write(IsEmpty(x) & "") x=Empty document.write(IsEmpty(x) & "") x=Null document.write(IsEmpty(x)) Output: True False True False 16.8 IsNull

The IsNull function returns a Boolean value va lue that indicates whether a specified expression contains no valid data (Null). It returns True if expression is Null; otherwise, it returns False. Syntax IsNull(expression) Parameter expression

Description Required. An ex expression

Example 1 dim x document.write(IsNull(x) & "") x=10 document.write(IsNull(x) & "") x=Empty document.write(IsNull(x) & "") x=Null document.write(IsNull(x)) Output: False False False True 16.9 IsNumaeric

The IsNumeric function returns a Boolean value that indicates whether a specified expression can be evaluated as a number. It returns True True if the expression is recognized as a number; otherwise, it returns False. Note: If expression is a date the IsNumeric function will return False.

Syntax Page 53 of 69

VB Script Standard Functions IsNumeric(expression) Parameter expression

Description Required. An ex expression

Example 1 dim x x=10 document.write(IsNumeric(x) & "") x=Empty document.write(IsNumeric(x) & "") x=Null document.write(IsNumeric(x) & "") x="10" document.write(IsNumeric(x) & "") x="911 Help" document.write(IsNumeric(x)) Output: True True False True False 16.10 IsObject

The IsObject function returns a Boolean value that indicates whether the specified expression is an automation object. It returns True if expression is an automation object; otherwise, it returns False. Syntax IsObject(expression) Parameter

Description

expression Required. An ex expression Example 1 dim x set x=me document.write(IsObject(x)) Output: True 16.11 LoadPicture

The LoadPicture function returns a picture object. Graphics formats that is recognized by the LoadPicture LoadPic ture function: Page 54 of 69

VB Script Standard Functions  bitmap files (.bmp) icon files (.ico) run-length encoded files (.rle) metafile files (.wmf) enhanced metafiles (.emf) GIF files (.gif) JPEG files (.jpg) • • • • • • •

Note: This function is available only on 32-bit platforms.

Syntax LoadPicture(picturename) Parameter  picturename

Description Required. The name of the picture file to be loaded

16.12 MsgBox

The MsgBox function displays a message box, waits for the user to click a button, and returns a value that indicates which button the user clicked. The MsgBox function can return one of the following values: • • • • • • •

1 = vbOK - OK was clicked 2 = vbCancel - Cancel was clicked 3 = vbAbort - Abort was clicked 4 = vbRetry - Retry was clicked 5 = vbIgnore - Ignore was clicked 6 = vbYes - Yes was clicked 7 = vbNo - No was clicked

Note: The user can press F1 to view the Help topic when both the helpfile and the context  parameter are specified. Tip: Also look at the InputBox function.

Syntax MsgBox(prompt[,buttons][,title][,helpfile,context]) Parameter prompt

Description Required. The message to show in the message box. Maximum length is 1024 characters. You can separate the lines using a carriage return character (Chr(13)), a linefeed character (Chr(10)), or carriage return–  linefeed character combination (Chr(13) & Chr(10)) between each line

buttons

Optional. A value or a sum of values that specifies the number and type of buttons to display, the icon style to use, the identity of the default  button, and the modality of the message box. Default value is 0 Page 55 of 69

VB Script Standard Functions • • • • • • • • • • • • • • •



title help elpfile cont ontext ext

0 = vbOKOnly - OK button only 1 = vbOKCancel - OK and Cancel buttons 2 = vbAbortRetryIgnore - Abort, Retry, and Ignore buttons 3 = vbYesNoCancel vbYesNoCancel - Yes, Yes, No, and Cancel buttons 4 = vbYesNo - Yes and No buttons 5 = vbRetryCancel - Retry and Cancel buttons 16 = vbCritical - Critical Message icon 32 = vbQuestion - Warning Warning Query icon 48 = vbExclamation vbEx clamation - Warning Warning Message icon 64 = vbInformation - Information Message icon 0 = vbDefaultButton1 - First button is default 256 = vbDefaultButton2 - Second button is default 512 = vbDefaultButton3 - Third button is default 768 = vbDefaultButton4 - Fourth button bu tton is default 0 = vbApplicationModal - Application modal (the current application will not work until the user responds to the message  box) 4096 = vbSystemModal - System modal (all applications wont work until the user responds to the message box)

We can divide the buttons values into four groups: The first group (0–5) describes the buttons to be displayed in the message box, the second group (16, 32, 48, 64) describes the icon style, the third group (0, 256, 512, 768) indicates which button is the default; and the fourth group (0, 4096) determines the modality of the message box. When adding numbers to create a final value for the buttons parameter, use only one number from each group Optional. The title of of the message bo box. Default is the application name Optiona onal. The The name ame of of a Help fi file to to us use. Must be be us used wi with th the co context  parameter  Optiona onal. The Help co context num numb ber to th the He Help to topic. Mu Must be be us used with the helpfile parameter 

Example 1 dim answer  answer=MsgBox("Hello everyone!",65,"Example") document.write(answer) 16.13 RGB

The RGB function returns a number nu mber that represents an RGB color value. Syntax RGB(red,green,blue) Parameter red

Description Required. A number from 0 to 255, inclusive, representing the red component of the color 

Page 56 of 69

VB Script Standard Functions green Required. A number from 0 to 255, inclusive, representing the green component of the color  blue Required. A number from 0 to 255, inclusive, representing the blue component of the color  Example 1 document.write(rgb(255,0,0)) Output: 255 16.14 Round

The Round function rounds a number. Syntax Round(expression[,numdecimalplaces]) Parameter expr xpression

Description Requi quired. The nu numeric ex express ession to to be be ro rounded ded

numdecimalplaces Optional. Specifies how many places to the right of the decimal are included in the rounding. Default is 0 Example 1 dim x x=24.13278 document.write(Round(x)) Output: 24 16.15 Script Engine

The ScriptEngine function returns the scripting language in use. This function can return one of the following strings: •

• •

VBScript - Indicates that Microsoft Visual Visual Basic Scripting Edition is the current scripting engine JScript - Indicates that Microsoft JScript is the current scripting engine VBA - Indicates that Microsoft Visual Visual Basic for Applications is the current scripting engine

Syntax ScriptEngine Example 1 document.write(ScriptEngine & "") Output: Page 57 of 69

VB Script Standard Functions VBScript 16.16 ScriptEngineBuildVersion

The ScriptEngineBuildVersion ScriptEngineBuildVersion function returns the build version number of the scripting engine in use Syntax ScriptEngineBuildVersion Example 1 document.write(ScriptEngineBuildVersion document.write(ScriptEngineBuildV ersion & "") Output: 6330 16.17 ScriptEngineMajorVersion Function

The ScriptEngineMajorVersion ScriptEngineMajorVersion function returns the major version number of the scripting engine in use Syntax ScriptEngineMajorVersion Example 1 document.write(ScriptEngineMajorVersion document.write(ScriptEngineMajorV ersion & "") Output: 5 16.18 ScriptEngineMinorVersion Function

The ScriptEngineMinorVersion ScriptEngineMinorVersion function returns the minor version number of the scripting engine in use. Syntax ScriptEngineMinorVersion Example 1 document.write(ScriptEngineMinorVersion) Output: 5 16.19 SetLocate

The SetLocale function sets the locale ID and returns the previous locale ID.

Page 58 of 69

VB Script Standard Functions A locale contains a set of user preference information: like language, cou ntry, region, and cultural conventions. The locale determines such things as keyboard layout, sort order, date, time, number, and currency formats. Syntax SetLocale(lcid) Parameter lcid

Description Required. A short string, hex value, or decimal value in the Locale ID chart, that identifies a geographic locale. If the lcid parameter is set to 0, the locale will be set by the system

Example 1 document.write(SetLocale(2057)) document.write(SetLocale(2058)) Output: 1033 2057 16.20 TypeName

The TypeName function returns the subtype of a specified variable. The TypeName function can return one of the following values: • • • • • • • • • • • • • • • • •

Byte - Indicates a byte value Integer - Indicates an integer value Long - Indicates a long integer value Single - Indicates a single-precision floating-point value Double - Indicates a double-precision floating-point value Currency - Indicates a currency value Decimal - Indicates a decimal value Date - Indicates a date or time value String - Indicates a character string value Boolean - Indicates a boolean value; True or False Empty - Indicates an unitialized variable  Null - Indicates no valid data - Indicates the actual type name of an object Object - Indicates a generic object Unknown - Indicates an unknown object type  Nothing - Indicates an object variable that doesn't yet refer to an object instance Error - Indicates an error 

Page 59 of 69

VB Script Standard Functions Syntax TypeName(varname) Parameter varname

Description Required. A variable name

Example 1 dim x x="Hello World!" document.write(TypeName(x) & "") />") />")

16.21 VarType

The VarType function returns a value that indicates the subtype of a specified variable. The VarType function can return one of the following values: • • • • • • • • • • • • •

0 = vbEmpty - Indicates Empty (uninitialized) 1 = vbNull - Indicates Null (no valid data) 2 = vbInteger - Indicates an integer  3 = vbLong - Indicates a long integer  4 = vbSingle - Indicates a single-precision floating-point number  5 = vbDouble - Indicates a double-precision floating-point number  6 = vbCurrency - Indicates a currency 7 = vbDate - Indicates a date 8 = vbString - Indicates a string 9 = vbObject - Indicates an automation object 10 = vbError - Indicates an error  11 = vbBoolean - Indicates a boolean 12 = vbVariant - Indicates a variant (used only with arrays of Variants) Page 60 of 69

VB Script Standard Functions 13 = vbDataObject - Indicates a data-access object 17 = vbByte - Indicates a byte 8192 = vbArray - Indicates an array • • •

Syntax VarType(varname) Parameter varname

Description Required. A variable name

Example 1 dim x x="Hello World!" document.write(VarType(x) & x=4 document.write(VarType(x) & x=4.675 document.write(VarType(x) & x=Null document.write(VarType(x) & x=Empty document.write(VarType(x) & x=True document.write(VarType(x)) Output: 8 2 5 1 0 11

"") "") "") "") "")

17. For Loop Syntax For counter = start To end [Step step]  statements] [ statements [Exit For] [ statements  statements] Next Arguments

counter   Numeric variable used as a loop counter. The variable can't be an array element or  an element of a user-defined type.  start  Initial value of counter . end  Final value of counter .

Page 61 of 69

VB Script Standard Functions  step Amount counter is changed each time through the loop. If not specified, step defaults to one.  statements One or more statements between For and Next that are executed the specified number of times. Remarks

The step argument can be either positive or negative. The value of the step argument determines loop processing as follows: Value Pos Positive or or 0 Negative

Loop executes if   count unter 10 Then A = A + 1 : B = B + A : C = C + B

When executing a block If (second syntax), condition is tested. If condition is True, the statements following Then are executed. If condition is False, each ElseIf  (if any) is evaluated in turn. When a True condition is found, the statements following the associated Then are executed. If none of the ElseIf  statements are True (or there are no ElseIf  clauses), the statements following Else are executed. After executing the statements following Then or Else, execution continues with the statement following End If . The Else and ElseIf  clauses are both optional. You can have as many ElseIf  statements as you want in a block If , but none can appear after the Else clause. Block If statements can  be nested; that is, contained within one another. What follows the Then keyword is examined to determine whether or not a statement is a  block If . If anything other than a comment appears after Then on the same line, the statement is treated as a single-line If statement. A block If statement must be the first statement on a line. The block If must end with an End If statement. Page 65 of 69

VB Script Standard Functions

21.Sub Routine Syntax Declares the name, arguments, and code that form the body of a Sub procedure. [Public [Default ] | Private ] Sub name [(arglist )] [ statements] [Exit Sub] [ statements] End Sub Arguments

 Public

Indicates that the Sub procedure is accessible to all other procedures in all scripts.  Default  Used only with the Public keyword in a Class block to indicate that the Sub  procedure is the default method for the class. An error occurs if more than one Default procedure is specified in a class.  Private Indicates that the Sub procedure is accessible only to other procedures in the script where it is declared. name  Name of the Sub; follows standard variable naming conventions. arglist  List of variables representing arguments that are passed to the Sub procedure when it is called. Commas separate multiple variables.  statements Any group of statements to be executed within the body of the Sub procedure. The arglist argument has the following syntax and parts: [ByVal | ByRef ] varname[( )] Arguments

 ByVal 

Indicates that the argument is passed by value.  ByRef 

Indicates that the argument is passed by reference. varname  Name of the variable representing the argument; follows standard variable naming conventions. Remarks

If not explicitly specified using either Public or Private , Sub procedures are public by default, that is, they are visible to all other procedures in your script. The value of local variables in a Sub procedure is not preserved between calls to the procedure.

Page 66 of 69

VB Script Standard Functions You can't define a Sub procedure inside any other procedure (e.g. Function or Property Get). The Exit Sub statement causes an immediate exit from a Sub procedure. Program execution continues with the statement that follows the statement that called the Sub  procedure. Any number of Exit Sub statements can appear anywhere in a Sub procedure. Like a Function procedure, a Sub procedure is a separate procedure that can take arguments, perform a series of statements, and change the value of its arguments. However, unlike a Function procedure, which returns a value, a Sub procedure can't be used in an expression. You call a Sub procedure using the procedure name followed by the argument list. See the Call statement for specific information on how to call Sub procedures. Caution Sub procedures can be recursive, that is, they can call themselves to perform a given task. However, recursion can lead to stack overflow.

Variables used in Sub procedures fall into two categories: those that are explicitly declared within the procedure and those that are not. Variables that are explicitly declared in a procedure (using Dim or the equivalent) are always local to the procedure. Variables that are used but not explicitly declared in a procedure are also local, unless they are explicitly declared at some higher level outside the procedure. Caution A procedure can use a variable that is not explicitly declared in the procedure,  but a naming conflict can occur if anything you have defined at the script level has the same name. If your procedure refers to an undeclared variable that has the same name as another procedure, constant or variable, it is assumed that your procedure is referring to that script-level name. To avoid this kind of conflict, use an Option Explicit statement to force explicit declaration of variables.

22.Function Syntax [Public [Default ] | Private ] Function name [(arglist )] [ statements] [name = expression] [Exit Function] [ statements] [name = expression] End Function Arguments

 Public

Indicates that the Function procedure is accessible to all other procedures in all scripts.  Default  Page 67 of 69

VB Script Standard Functions Used only with the Public keyword in a Class block to indicate that the Function  procedure is the default method for the class. An error occurs if more than one Default procedure is specified in a class.  Private Indicates that the Function procedure is accessible only to other procedures in the script where it is declared or if the function is a member of a class, and that the Function procedure is accessible only to other procedures in that class. name  Name of the Function ; follows standard variable naming conventions. arglist  List of variables representing arguments that are passed to the Function  procedure when it is called. Commas separate multiple variables.  statements Any group of statements to be executed within the body of the Function  procedure. expression Return value of the Function . The arglist argument has the following syntax and parts: [ByVal | ByRef ] varname[( )] Arguments

 ByVal 

Indicates that the argument is passed by value.  ByRef 

Indicates that the argument is passed by reference. varname  Name of the variable representing the argument; follows standard variable naming conventions. Remarks

If not explicitly specified using either Public or Private , Function procedures are public  by default, that is, they are visible to all other procedures in your script. The value of  local variables in a Function is not preserved between calls to the procedure. You cannot define a Function procedure inside any other procedure (e.g. Sub or  Property Get ). The Exit Function statement causes an immediate exit from a Function procedure. Program execution continues with the statement that follows the statement that called the Function procedure. Any number of Exit Function statements can appear anywhere in a Function procedure. Like a Sub procedure, a Function procedure is a separate procedure that can take arguments, perform a series of statements, and change the values of its arguments. However, unlike a Sub procedure, you can use a Function procedure on the right side of  Page 68 of 69

VB Script Standard Functions an expression in the same way you use any intrinsic function, such as Sqr, Cos, or Chr, when you want to use the value returned by the function. You call a Function procedure using the function name, followed by the argument list in  parentheses, in an expression. See the Call statement for specific information on how to call Function procedures. Caution Function procedures can be recursive, that is, they can call themselves to  perform a given task. However, recursion can lead to stack overflow.

To return a value from a function, assign the value to the function name. Any number of  such assignments can appear anywhere within the procedure. If no value is assigned to name, the procedure returns a default value: a numeric function returns 0 and a string function returns a zero-length string (""). A function that returns an object reference returns Nothing if no object reference is assigned to name (using Set) within the Function .

Page 69 of 69

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF