VBS learning Diary (ii) basic knowledge

Source: Internet
Author: User
Tags array definition

VBScript Basics
One, variable
1. the contents behind all the single quotes are interpreted as gaze。 (Ctrl+m gaze in vbsedit, anti-gaze ctrl+shift+m)
2. In VBScript, the naming rules for variables follow the standard naming conventions, and it is important to note that: references to variables, methods, functions, and objects in VBScript are not case-sensitive to uppercase and lowercase。 To explicitly declare a variable when declaring a variable, you need to use keyword DIm to tell VBScript that you want to create a variable and then follow the variable name. declare multiple variables of the same type and can be separated by commas。 Note: in VBScript variables are assigned at the same time when they are intended to declare variables。 But agreed to Two variables are assigned at the same time in one line of code, separated by colons
3. YouThe ability to use Option Explicit to tell the host that a variable must be declared before using the。
4. VBScript only has a variable type when it is defined, and in practice it is necessary to use a type conversion function to convert the variable to the corresponding variable type.
The CBool function converts a variable into a Boolean value;
The CByte function converts a variable to an integer between 0 and 255.
The Ccur function, the CDBL function, and the CSNG function convert the variable to a floating-point value, which is only accurate to four digits after the decimal point, and the latter two are more accurate and the range of values is much larger.

The Cdate function converts a variable to a date value.
The Cint function and the CLNG function convert the variable to an integer, which has a much larger range than the former.
The CSTR function converts a variable to a string.
Second, array

The definition of an array is similar to a variable, and it is only necessary to describe the number and dimensions of the array after the variable. It is important to note that the subscript of an array always starts at 0, and the value in the array definition is reduced by one end. That means you want to define an array of 10 data that will write the code: the DIm Array (9), the same, when you want to access the Fifth element, the actual code is arr ay (4). Of course, you can declare a dynamic array by not specifying the number and dimensions of the array. When the number of arrays and the number of dimensions are fixed, use keywordredim to change the array . Note that when changing the size of an array, the data of the array is destroyed and the data is protected using keyword preserve .

Like what:

RedIm Space Preserve space array parentheses number comma dimension parentheses

Three, operator
In the VBScript operator, subtraction are the symbols we use most often, using the ^, modulo Mod used. In the comparison operator, equal, less than, greater than, less than, equal to, greater than or equal to the symbols we often use are consistent, and unequal then less than and greater than the conjunction。
The logical operators are: and operate->and non-operational->not or operations->or;
You can use operator + and operator & to concatenate strings, general use of & operator
The other one is more special. operator is used to compare objects, such as a button object, assuming object is the same type, the result is true, assuming that the object is not the same type, the result is false

Iv. conditional statements

There are mainly two forms of If......then statement and Selectcase statement

In the If......then statement, the basic form is:
If condition Then
The statement of the processing condition;
......

Endif

The basic form can only validate a single condition, assuming that there are two conditions, you need to add a single statement in the basic form else, if there are many other conditions to be verified, you need to add a statement ElseIf condition then processing condition statement
In the Selectcase statement, the basic form is:
Select Case Variable
Case Condition Value
Processing condition Statements
and repeated the last two sentences.
The last sentence should be
Case Else

Processing statements
Of course, don't forget to put the conditional closing sentence End Select on the last line
Note: When you run a string, you need to pay special attention to uppercase and lowercase, and in general, before we compare, Use the LCase function to convert a string to lowercase and use the UCase function to translate the string to uppercase
v. Circular control Statements
loop control statements have a for ... next loop, for ... Each loop, Do......while loop, Do......until Loop, while loop five forms.
Before using the loop control statement, the loop condition is first inferred, assuming that the number of cycles is fixed, then using the For......next loop, the structure is:
For counter variable = start Count value to last count value
Running the loop body
Next
Assuming that each element in the array or object collection needs to be inferred, you need to use the for ... Each loop, which is structured as:
For Each loop count variable in the object or array to view
To run a processing statement
Next
Note: In the aboveYou can use Exit for to exit the loop at any time in two loops
Suppose you want to when the condition is metRunning a piece of code uses the Do......while statement, which is structured as:
Do and condition
Running the loop body
Loop
Suppose you want to when the condition is not satisfiedTo run the code, use the Do......until statement with the structure:
Do Until conditions
Running the loop body
Loop
Of course In both of these loop statements, you can use Exit do to exit the loopThe last loop statement is run the loop until the condition is met
While condition
Running the loop body
Wend
Vi. Use of the process
There are two kinds of processes that are used frequently, one is a function, a return value to the caller, a subroutine, no return value, and another called special subroutines for events, using less.
The basic method of defining a function is:
Function name (List of parameters)
function code
Function name = value ' used to return a value
End Function
Subroutine some are similar, just no return value
Attention: Although in the definition of subroutines, the list of references to parentheses, but when the subroutine is called, the table does not addParentheses, parentheses are used only in functions. Other than that A subroutine cannot be used in an expression。 And the function can only be present on the right side of an assignment statement, or in an expression, function cannot be used directly, assuming that the function must be used directly, the You must use the Call statement and cancel the return value

VBS learning Diary (ii) basic knowledge

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.