Google

Sunday, January 13, 2008

Vb Script Tutorial

10.13 Minute
The Minute function returns a number between 0 and 59 that represents the minute of the hour.
Syntax
Minute(time)

Parameter
Description
time
Required. Any expression that can represent a time
Example 1
document.write(Now & "
")document.write(Minute(Now))Output:1/15/2002 10:34:39 AM34
10.14 Month
The Month function returns a number between 1 and 12 that represents the month of the year.
Syntax
Month(date)

Parameter
Description
date
Required. Any expression that can represent a date
Example 1
document.write(Date & "
")document.write(Month(Date))Output:1/15/20021
10.15 MonthName
The MonthName function returns the name of the specified month.
Syntax
MonthName(month[,abbreviate])

Parameter
Description
month
Required. Specifies the number of the month (January is 1, February is 2, etc.)
abbreviate
Optional. A Boolean value that indicates if the month name is to be abbreviated. Default is False
Example 1
document.write(MonthName(8))Output:August
10.16 Now
The Now function returns the current date and time according to the setting of your computer's system date and time.
Now
Example 1
document.write(Now)Output:1/15/2002 10:52:15 AM

Vb Script Tutorial

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

Parameter
Description
date
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
Description
time
Required. Any expression that can represent a time
Example 1
document.write(Now & "
")document.write(Hour(Now))Output:1/15/2002 10:07:47 AM10
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
IsDate(expression)

Parameter
Description
expression
Required. The expression to be evaluated
Example 1
document.write(IsDate("April 22, 1947") & "
")document.write(IsDate(#11/11/01#) & "
")document.write(IsDate("#11/11/01#") & "
")document.write(IsDate("Hello World!"))Output:TrueTrueFalseFalse

Vb Script Tutorial

10.7 DateSerial
The DateSerial function returns a 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. For all other year arguments, use a complete four-digit year
month
Required. Any numeric expression
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/19966/30/1970
10.8 DateValue
The DateValue function returns a 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 from January 1, 100 through December 31, 9999 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") & "
")document.write(DateValue("31-Jan-02 2:39:49 AM"))Output:1/31/20021/31/20021/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
Description
date
Required. Any expression that can represent a date
Example 1
document.write(Date & "
")document.write(Day(Date))Output:1/14/200214

Vb Script Tutorial

10.6 DatePart
The DatePart function returns the specified part of a given date.
Syntax
DatePart(interval,date[,firstdayofweek[,firstweekofyear]])

Parameter
Description
interval
Required. The interval of time to 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
date
Required. Date expression to evaluate
firstdayofweek
Optional. Specifies the day of the week.
Can take the following values:
0 = vbUseSystemDayOfWeek - Use National Language Support (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
firstweekofyear
Optional. Specifies the first week of the 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 - Start with the first full week of the new year
Example 1
document.write(Date & "
")document.write(DatePart("d",Date))Output:1/14/200214

Vb Script Tutorial

10.4 DateAdd
The DateAdd function returns a date to which a specified time interval has been added.
Syntax DateAdd(interval,number,date)
Parameter
Description
interval
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
number
Required. The number of interval you want to add. Can either be positive, for dates in the future, or negative, for dates in the past
date
Required. Variant or literal representing the date to which interval is added
Example 1
'Add one month to January 31, 2000document.write(DateAdd("m",1,"31-Jan-00"))Output:2/29/2000
Example 2
'Add one month to January 31, 2001document.write(DateAdd("m",1,"31-Jan-01"))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
interval
Required. The interval you want to use to calculate the differences 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
date1,date2
Required. Date expressions. Two dates you want to use in the calculation
firstdayofweek
Optional. Specifies the day of the week.
Can take the following values:
0 = vbUseSystemDayOfWeek - Use National Language Support (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
firstweekofyear
Optional. Specifies the first week of the 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 - 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/200211351505440

Vb Script Tutorial

10. Date / Time Functions Syntax with Example
10.1 Write Text: How to write text on a page

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
Description
date
Required. Any valid date expression (like Date() or Now())
Example 1
d="April 22, 2001"if IsDate(d) then document.write(CDate(d))end ifOutput:2/22/01

Example 2
d=#2/22/01#if IsDate(d) then document.write(CDate(d))end ifOutput:2/22/01
Example 3
d="3:18:40 AM"if IsDate(d) then document.write(CDate(d))end ifOutput:3:18:40 AM
10.3 Date
The Date function returns the current system date
Syntaxdocument.write("The current system date is: ")document.write(Date)Output:
The current system date is: 1/14/2002

Vb Script Tutorial



7. Array Functions
Function
Description
Array
Returns a variant containing an array
Filter
Returns a zero-based array that contains a subset of a string array based on a filter criteria
IsArray
Returns a Boolean value that indicates whether a specified variable is an array
Join
Returns a string that consists of a number of substrings in an array
LBound
Returns the smallest subscript for the indicated dimension of an array
Split
Returns a zero-based, one-dimensional array that contains a specified number of substrings
UBound
Returns the largest subscript for the indicated dimension of an array


8. String Functions
Function
Description
InStr
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
LCase
Converts a specified string to lowercase
Left
Returns a specified number of characters from the left side of a string
Len
Returns the number of characters in a string
LTrim
Removes spaces on the left side of a string
RTrim
Removes spaces on the right side of a string
Trim
Removes spaces on both the left and the right side of a string
Mid
Returns a specified number of characters from a string
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 of a specified length
StrReverse
Reverses a string
UCase
Converts a specified string to uppercase

9. Other Functions

Function
Description
CreateObject
Creates an object of a specified type
Eval
Evaluates an expression and returns the result
GetLocale
Returns the current locale ID
GetObject
Returns a reference to an automation object from a file
GetRef
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. Available only on 32-bit platforms
MsgBox
Displays a message box, waits for the user to click a button, and returns a value that indicates which button the user clicked
RGB
Returns a number that represents an RGB color 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 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

Vb Script Tutorial

4. Conversion Functions

Function
Description
Asc
Converts the first letter in a string to ANSI code
CBool
Converts an expression to a variant of subtype Boolean
CByte
Converts an expression to a variant of subtype Byte
CCur
Converts an expression to a variant of subtype Currency
CDate
Converts a valid date and time expression to the variant of subtype Date
CDbl
Converts an expression to a variant of subtype Double
Chr
Converts the specified ANSI code to a character
CInt
Converts an expression to a variant of subtype Integer
CLng
Converts an expression to a variant of subtype Long
CSng
Converts an expression to a variant of subtype Single
CStr
Converts an expression to a variant of subtype String
Hex
Returns the hexadecimal value of a specified number
Oct
Returns the octal value of a specified number

5. Format Functions
Top

Function
Description
FormatCurrency
Returns an expression formatted as a currency value
FormatDateTime
Returns an expression formatted as a date or time
FormatNumber
Returns an expression formatted as a number
FormatPercent
Returns an expression formatted as a percentage

6. Math Functions
Top

Function
Description
Abs
Returns the absolute value of a specified number
Atn
Returns the arctangent of a specified number
Cos
Returns the cosine of a specified number (angle)
Exp
Returns e raised to a power
Hex
Returns the hexadecimal value of a specified number
Int
Returns the integer part of a specified number
Fix
Returns the integer part of a specified number
Log
Returns the natural logarithm of a specified number
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
Tan
Returns the tangent of a specified number (angle)

Thursday, January 10, 2008

VB Script1

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, or at a later event.
Function
Description
CDate
Converts a valid date and time expression to the variant of subtype Date
Date
Returns the current system date
DateAdd
Returns a date to which a specified time interval has been added
DateDiff
Returns the number of intervals between two dates
DatePart
Returns the specified part of a given date
DateSerial
Returns the date for a specified year, month, and day
DateValue
Returns a date
Day
Returns a number that represents the day of the month (between 1 and 31, inclusive)
FormatDateTime
Returns an expression formatted as a date or time
Hour
Returns a number that represents the hour of the day (between 0 and 23, inclusive)
IsDate
Returns a Boolean value that indicates if the evaluated expression can be converted to a date
Minute
Returns a number that represents the minute of the hour (between 0 and 59, inclusive)
Month
Returns a number that represents the month of the year (between 1 and 12, inclusive)
MonthName
Returns the name of a specified month
Now
Returns the current system date and time
Second
Returns a number that represents the second of the minute (between 0 and 59, inclusive)
Time
Returns the current system time
Timer
Returns the number of seconds since 12:00 AM
TimeSerial
Returns the time for a specific hour, minute, and second
TimeValue
Returns a time
Weekday
Returns a number that represents the day of the week (between 1 and 7, inclusive)
WeekdayName
Returns the weekday name of a specified day of the week

The Blog Is A Discussion Of Vb Script

The Blog Is A Discussion Of Vb Script