VBScript Learning Notes

Source: Internet
Author: User
Tags date1 map class

Because we're going to test a Web project with QTP next week, it took some time tonight to re-learn the VBScript syntax. Just know that VBScript only supports IE browser and is not supported for other browsers.

The following is a brief introduction to some syntax:

1. VBScript is case-insensitive and supports space, tab, and Space tab blending using the Indent method. This is the exact opposite of Python.

2. There are three ways to declare a variable: Dim, public, Private

Dim var Dim declares that the variable is accessed by the script or the procedure in the script, depending on where it is located. is determined by its scope.

Public var this declared variable can be accessed by any script and procedure in an HTML page

Private var this declared variable can only be accessed in this script

3. You can use dim when declaring variables in VBScript, but not for different data types depending on the assignment:

Data replication: Dim data

String copy: Dim strvalue, strvalue = "String Value"

Time and Date: Dim date_time, date_time = #12:30:40 pm#

Dim Date1, Date1 = #11/30/2014#

4. Array declaration method: Dim Array (5), although the size of the array is 5, but can contain 6 values. Starting with Array (0) to Array (5), this is not the same as in other languages.

5. When writing code, you can use the with ... End with the number of shorthand codes.

6. In the first line of the code, add: Option Explicit. In this case, the following code, as long as the variable is declared, you must assign a value, otherwise it will be an error.

7. Use some variants methods, such as: IsArray, IsEmpty, IsNull, IsNumeric, IsObject, TypeName, etc. can be judged on some variables, arrays, characters, objects.

8. You can use the 2 method to add comments.

<!-

' This is example 1!

-

Or

<!-

REM this is Example 2!!! Starts with REM

-

9. Function and sub actually write some code that needs to be written in one piece (they are called procedure, which is the block), but there are differences:

Function: You can have a return value, or you can have parameters with people. Call Function_name (Parameters) to invoke the function method

Sub: No return value, no parameters. Call the Sub method, directly write the name of the sub can be sub_name.

10. In VBScript, an object is a very important thing, and we can use it as a common object, based on these objects.

Create object: Dim objectname

Set objectname = CreateObject ("Scripting.Dictionary")

Destroying objects: Set objectname = Nothing

A brief introduction to the Dictionary object, which resembles the Java map class, is the form of key-value. For the processing of data this piece, has a great help.

There are also FileSystemObject objects, which can be used to manipulate files, similar to the Java file class.

11. More than VBScript version 5.0, which supports object-oriented programming, is a surprise. Here's how to use it:

' Defining the Classclass classname    'Declareobject name...  EndClass' instantiation of the classset objectname = new classname

VBScript Learning Notes

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.