Quick check of VBScript grammar and illustration of _vbs

Source: Internet
Author: User
Tags abs chr comparison lowercase numeric value rtrim

VBScript functions

Function description
Example
ABS (value) absolute value. The absolute value of a number is its positive value. The absolute value of an empty string (null), also an empty string. Uninitialized variables, which are absolutely 0 examples: ABS (-2000)
Results: 2000

Array (a comma-delimited array element) Array function returns the value of an array element. Example:
A=array (1,2,3)
B=a (2)
Results: 2
Description: Variable B is the value of the second element of array A.

ASC (String) converts the first letter of the string to ANSI (American National standard symbol) codewords. Example: ASC (Internet)
Results: 73
Description: Displays the ANSI codewords of the first letter I.


CBool (expression) conversion to Boolean logical value variable form (TRUE or FALSE) Example: CBool (1+2)
Result: True


The CDate (date expression) is replaced by a date variable type. You can use the IsDate function to determine whether a date could be converted. Example: CDate (now () +2)
Results: 2000/5/28 10:30:59


The CDBL (expression) is converted to a double variable type.


CHR (ANSI codewords) converts ASCII codewords to characters. Example: Chr (72)
Result: H


The CInt (expression) is converted to an integer variable form. Example: CInt ("3.12")
Results: 3


The CLng (expression) is converted to a long variable type.


The CSng (expression) is converted to a single variable type.


The CSTR (expression) is converted to a string variable type.


Date () Top returns the day of the system. Example: Date
Results: 2000/5/13
DATEADD (I, N, D) adds a date after a period of time. I: Set the unit for a period of time (date). For example, interval= "D" means the unit of n is the day. The setting value of I is as follows:
YYYY year
Q Quarter Season
M Month Month
D Day
W Weekday Week
H Hour Time
N-Minute
S Second sec
N: A numeric expression that sets a period of time added by a date, either positive or negative, positive (the result is >date date), and negative for minus (the result is >date previous date).
D: The date to be added and reduced. Example: DateAdd ("M", 1, "31-jan-98")
Result: 28-feb-98
Note: Add the date 31-jan-98 one months, the result is 28-feb-98 rather than 31-fe-98.
Example: DateAdd ("D", "30-jan-99")
Results: 1999/2/9
Description: Add a date 30-jan-99 20 days after the date.


DateDiff (I, D1, D2[,fw[,fy]) calculates the period between two dates.
I: Set the unit of the period calculation between two dates. For example, >i= "m" means the unit of calculation is month. >i setting values are as follows:
yyyy > Year
Q Quarter Season
M Month Month
D Day
W Weekday Week
H Hour Time
M-Minute
S Second sec
D1, D2: Two date expressions in the calculation period, if >date1 earlier, the period result between two dates is positive; if >date2 earlier, the result is negative.
FW: Sets the first day of the week for the week, if not set for Sunday. The set values for >FW are as follows:
0 Use the set value of >api.
1 Sunday
2 Monday
3 Tuesday
4 Wednesday
5 week Four
6 Friday
7 Saturday
FY: Setting the first week of the year, if not set, means that the week of January 1 is the first week of the year. The set values for >fy are as follows:
0 Use the set value of >api.
1 January 1 The week is the first week of the year
2 include at least four days of the first week of the first week of the year
3 includes the first week of seven days as the first week of the Year: DateDiff ("D", "25-mar-99", "30-jun-99")
Results: 97
Description: Displays the period between two dates as 97 days.
DatePart (I,d,[,fw[,fy]) returns the part of a date.
>i: Set it back to that part. For example, >i= "D" means to return part of the day. The set values for >i are as follows:
YYYY year
Q Quarter Season
M Month Month
D Day
W Weekday Week
H Hour Time
M-Minute
S Second sec
D: the date to be calculated.
>FW: Set the first day of the week for the weekday, if not set for Sunday. The set values for >FW are as follows:
0 Use the set value of >api.
1 Sunday
2 week one >3 Tuesday
4 Wednesday
5 week Four
6 Friday
7 Saturday
FY: Setting the first week of the year, if not set, means that the week of January 1 is the first week of the year. The set values for >fy are as follows:
0 Use the set value of >api.
1 January 1 The week is the first week of the year
2 include at least four days of the first week of the first week of the year
3 includes the first week of seven days as the first week of the Year: DatePart ("M", "25-mar-99")
Results: 3
Description: Displays the month part that returns a date.


Dateserial (year,month,day) conversion (Year,month,day) into a date variable type. Example: DateSerial (99,10,1)
Results: 1999/10/1


The DateValue (string or expression of the date) is converted to a date variable type, dated from January 1,100 to December 31,9999. The format is Month,day,and year or month/day/year. For example: December 30,1999, Dec 30,1999, 12/30/1999, 12/30/99 Examples: DateValue ("January 1,2002")
Results: 2002/1/1


Day (the string or expression of the date) returns the "days" part of the date. Example: Day ("12/1/1999")
Results: 1


The Fix (expression) top conversion string is an integer numeric form. Same as Int function. NULL is returned if NULL.
The difference between Int (number) and Fix (number) is negative. such as Int ( -5.6) =-6, Fix (-5.6) =-5. Example: Fix (5.6)
Results: 5
Hex (expression) top returns the hexadecimal value of a value. If the expression is null Hex (expression) =null, if the expression =empty Hex (expression) = 0. The 16 carry can be added "&h", for example, the 16 carry &H10 represents the decimal 16. Example: Hex (30)
Results: 1E


Hour (a string or expression of time) returns the "hour" portion of the time. Example: Hour ("12:30:54")
Results: 12


INSTR ([Start,]string1,string2[,compare]) top returns a string from the left and right to the other, returning to the same position as the first.
Start is a comparison from the first word, if the start is omitted from the beginning of the comparison, string1 for the string expression to be found, string2 for the string expression to be compared, compare for comparison, compare=0 table binary comparison method, compare =1 Table Text comparison method, if omitted compare is a preset binary comparison method. Example: InStr ("abc123def123", "12")
Results: 4


InStrRev ([Start,]string1,string2[,compare]) returns a string from the right and left to the other, returning to the first same position.
Start is a comparison from the first word, if the start is omitted from the beginning of the comparison, string1 for the string expression to be found, string2 for the string expression to be compared, compare for comparison, compare=0 table binary comparison method, compare =1 Table Text comparison method, if omitted compare is a preset binary comparison method. Example: InStrRev ("abc123def123", "12")
Results: 10


INT (expression) returns the integer portion of a numeric value. Same as the Fix function. Example: Int (5.6)
Results: 5


The IsArray (variable) test variable is (True) No (False) is an array. Example: IsArray (3)
Result: False
Description: Not an array.


Whether the IsDate (an expression of a date or string) can be converted to a date. Date from January 1,100 A.D to December 31,9999 A.D. Example: IsDate ("December 31,1999")
Result: True
Description: Can be converted to date.


The IsEmpty (variable) test variable is (True) No (False) An instance that has been initialized: IsEmpty (a)
Result: True
The IsNull (variable) test variable is (True) No (False) is not a valid data. Example: IsNull ("")
Result: False
Description: is valid data.

IsNumeric (the expression) is (True) No (False) is a number. Example: IsNumeric ("abc123")
Result: False
Description: Not a number.


The LCase (string expression) top conversion string is lowercase. Converts a portion of a capital letter to lowercase. The remaining parts of the string are unchanged. Example: LCase ("ABC123")
Result: abc123


Left (string expression, length) takes a few words on the left-hand side of the string. Length is a word. The Len function is able to learn the length of the string. Example: Left ("ABC123", 3)
Result: ABC

Len (string expression variable) Gets the length of the string. Example: Len ("ABC123")
Results: 6


LTrim (string expression) drops the blank word to the left of the string. RTrim removes the blank word on the right side of the string, and the Trim function drops the whitespace on both sides of the string. Example: LTrim ("456+", "abc")
Result: 456abc123


Mid (string expression, Start[,length]) top takes a few words from the string. Start is taken from the first few words, length to take a few words, if slightly length from start to the bottom right. The Len function allows you to know the length of the string. Example: Mid ("abc123", 2, 3)
Result: C12


Minute (a string or expression of a date) returns the "minute" portion of the time. Example: Minute ("12:30:54")
Results: 30


Month (a string or expression of a date) returns the "month" portion of the date. Example: Month ("12/1/2001")
Results: 12


MonthName (Month[,abbreviate]) returns the name of the month.
Month: The number 1~12 the name of the month to be returned. For example, 1 represents January, and 7 represents July.


Abbreviate: Yes (True) (False) is abbreviated, for example, March, abbreviated as Mar. The default value is False. The name of the month in Chinese is not abbreviated. Example: MonthName (7)
Results: July
Now () returns the date and time of the system. Example: Now ()
Results: 2001/12/30 10:35:59 AM


The OCT () returns the octet value of the value. Octal can be added to "&o", for example, the octal &o10 represents 8 of the decimal. Example: Oct (10)
Results: 12


Replace (string expression, Findnreplacewith[,start[,count[,compare]]) replaces a string with a partial word. Find the original string to be replaced (find) and replace it with the new string (replacewith) if found.


Find: The original string to be looked for instead.


ReplaceWith: Replace the word after.


Start: Look for the substitution from the first few words, if not set, then start looking for a word.


Count: Number of replacements. If not set, all the found strings are replaced by the string.


Compare: Looking for the comparison method, compare=0 represents the binary comparison method, Compare=1 table text comparison method, compare =2 table According to the comparison data type, if omitted
Compare is a preset binary comparison method. Example: Replace ("ABCD123ABC", "AB", "AB")
Result: ABCD123ABC
Right (string expression, length) takes a few words from the right-hand side of the string, and length takes several words. The Len function is able to learn the length of the string. Example: Right ("ABC123", 3)
Results: 123


Random random value of the Rnd [(number)] 0~1. Number is any valid numeric expression. A number less than 0 indicates that the same random random value is obtained each time. If number is greater than 0 or not provided, the next random random value is given sequentially. >number=0 represents the most recently generated random random value. In order to avoid the same random sequence of random numbers, we can add Randomize to the Rnd function. Example: Rnd
Results: 0.498498


Round (numeric expression [, D]) rounded.
D: Rounded to the decimal number, or rounded to an integer if omitted. Example: Round (30635,1)
Results: 3.6


RTrim (string expression) drops the blank word to the right of the string. LTrim to remove the blank word on the left side of the string, the Trim function drops the whitespace on both sides of the string. Example: RTrim ("abc123") + "456"
Result: abc123456


Second (string or expression of time) top returns the "seconds" portion of the time. Example: Second ("12:30:54")
Results: 54


Space (repeat times) gets the same blank string that repeats. Example: A "+space" (5) + "B"
Result: A B
Description: Add five blank words between A and B.


String (the number of repetitions, the word to be repeated) gets the same strings repeated. Example: String (5,71)
Result: GGGGG


StrReverse (String (10,71)) reverses the order of a string. Example: StrReverse ("ABC")
Results: CBA
Time () is returned to the system. Example: Time
Result: 10:35:59 PM


TimeSerial (Hour,minute,second) converts the specified (Hour,minute,second) into a time variable type. Example: TimeSerial (10,31,59)
Result: 10:31:59


The TimeValue (string or expression of the date) is converted to a time variable type. The string or expression of the date from 0:00:00 (12:00:00 a.m.) to 23:59:59 (11:59:59 p.m.). Example: TimeValue ("11:59:59")
Result: 11:59:59


Trim (string expression) removes whitespace from the left and right sides of the string. Example: Trim ("abc123")
Result: abc123


The UCase () top conversion string is capitalized. Converts a portion of a lowercase letter to uppercase and the rest of the string unchanged. Example: UCase ("abc123")
Result: ABC123


VarType (variable) returns a variable type. As with the TypeName function, VarType returns the code of the variable type, TYPENAME returns the name of the variable type. Example: VarType ("I Love you!")
Results: 8


Weekday (date expression, [FW]) returns the number of days of the week.
FW: Set the first day of the week is the week. If omitted, table 1 (Sunday).
Firstdayfweek setting values are: 1 (Sunday), 2 (Monday), 3 (Tuesday), 4 (Wednesday), 5 (Thursday), 6 (Friday), 7 (Saturday). Example: Weekday ("1/1/2000")
Results: 7


WeekdayName (W,A,FW) returns the name of the day of the week.
W: Is (True) No (False) abbreviation. For example, March, the abbreviation for the Mar. Default to False. The name of the week in Chinese is not abbreviated.
FW: Set the first day of the week is the week. If Table 1 (Sunday) is omitted. Sets the name of the day of the week to be returned, which is the first days of the week.
A:1 (Sunday), 2 (Monday), 3 (Tuesday), 4 (Wednesday), 5 (Thursday), 6 (Friday), 7 (Saturday). Example: WeekdayName ("1/1/2000")
Results: Saturday
Year () returns the "years" part of the date. Example: Year ("12/1/2000")
Results: 2000

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.