VBScript Tutorial eight-coding

Source: Internet
Author: User
Tags constant html page mixed naming convention variable scope
VBScript Coding Conventions
Coding conventions are some of the recommendations that help you write code using Microsoft Visual Basic scripting Edition. The encoding convention contains the following:
Naming conventions for objects, variables, and procedures
Annotation conventions
Text formatting and indenting guides
The main reason for using a consistent coding convention is to standardize the structure and coding style of a script or script set so that the code is easy to read and understand. Using good coding conventions makes the source code clear, readable, accurate, intuitive, and consistent with other language conventions.
Constant naming convention
Earlier versions of VBScript did not allow the creation of user custom constants. If you want to use constants, constants are implemented as variables, and all letters are capitalized to distinguish them from other variables. Multiple words in a constant name are separated by an underscore (_). For example:
User_list_max
New_line
This method of identifying constants is still possible, but you can also choose a different scenario and create a true constant with the Const statement. This convention uses a mixed-case format and is prefixed with "con" as a constant name. For example:
Conyourownconstant
Variable Naming conventions
To improve readability and consistency, use the following variable naming conventions in VBScript code:
Sub-type Prefix example
Boolean bln BlnFound
Byte byt Bytrasterdata
Date (time) DTM Dtmstart
Double Dbl dbltolerance
Error Err Errordernum
Integer int Intquantity
Long LNG lngdistance
Object obj objcurrent
Single SNG Sngaverage
String Str strFirstName
Variable scope
Variables should be defined in as small a scope as possible. The scope of the VBScript variable is as follows:
Scope declaration variables at the point of visibility
A procedure-level event, function, or child procedure.
Visible in the process of declaring a variable.
The head portion of the Script-level HTML page, outside of any process.
Visible in all procedures of the script.
Variable scope prefix
As the length of the script code increases, it is necessary to quickly differentiate the scope of the variable. Adding a single character prefix before the type prefix can accomplish this without causing the variable name to be too long.
Scope Prefix Example
Process level without dblvelocity
Script class S Sblncalcinprogress
Descriptive variable name and procedure name
The body of the variable or procedure name should be mixed with the case, and describe its purpose as fully as possible. In addition, the procedure name should begin with a verb, such as initnamearray or Closedialog.
For frequently used or longer names, it is recommended that the standard abbreviation be used to keep the name within the appropriate length. Variable names that are usually more than 32 characters become difficult to read. When using abbreviations, be sure to be consistent throughout the script. For example, switching Cnt and Count at random in one script or script set creates confusion.

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.