In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what is the VBScript coding convention", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn what is the VBScript coding convention!
Coding conventions are some suggestions to help you write code in Microsoft Visual Basic Scripting Edition. The coding convention includes the following:
Naming conventions for objects, variables, and procedures
Annotation convention
Guidelines for text formatting and indentation
The main reason for using consistent coding conventions is to standardize the structure and coding style of Script or Script sets so that the code is easy to read and understand. Using good coding conventions can make the source code clear, readable, accurate, more intuitive and consistent with other language conventions.
Constant naming convention
Previous versions of VBScript did not allow the creation of user-defined constants. If you want to use constants, the constants are implemented as variables, and all letters are capitalized to distinguish them from other variables. Multiple words in constant names are separated by an underscore (_). For example:
USER_LIST_MAX
NEW_LINE
This method of identifying constants is still possible, but there are other options for creating real constants with Const statements. This
The convention uses a mixed case format with "con" as the prefix for the constant name. For example:
ConYourOwnConstant
Variable naming convention
For readability and consistency, use the following variable naming convention in your VBScript code:
Example of subtype prefix
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 the smallest possible scope. The scope of the VBScript variable is as follows:
Visibility at scope declaration variables
Procedure-level events, functions, or subprocedures are visible in the process of declaring variables
The HEAD section of a Script-level HTML page, visible in all Script procedures except for any process
Variable scope prefix
As the length of Script code increases, it is necessary to quickly distinguish the scope of variables. Adding a single-character prefix to the type prefix can do this without causing the variable name to be too long.
Scope prefix exampl
No dblVelocity at process level
Script level s sblnCalcInProgress
Descriptive variable name and procedure name
The body of a variable or procedure name should use a mixed case format and describe its purpose as fully as possible. In addition, the procedure name should start with a verb, such as InitNameArray or CloseDialog.
For frequently used or longer names, it is recommended that you use standard abbreviations to keep the name within the appropriate length. Variable names that are usually more than 32 characters can become difficult to read. When using abbreviations, make sure that they are consistent throughout the Script. For example, switching between Cnt and Count at will in a Script or Script set can cause confusion.
Object naming convention
The following table lists the object naming conventions that may be used in VBScript (recommended):
Example of object type prefix
3D panel pnl pnlGroup
Animation button ani aniMailBox
Check box chk chkReadOnly
Combo box, drop-down list box cbo cboEnglish
Command button cmd cmdExit
Public Dialog Box dlg dlgFileOpen
Frame fra fraLanguage
Horizontal scroll bar hsb hsbVolume
Image img imgIcon
Label lbl lblHelpMessage
Straight line lin linVertical
List box lst lstPolicyCodes
Knob spn spnPages
Text box txt txtLastName
Vertical scroll bar vsb vsbRate
Slider sld sldScale
Code comment convention
The beginning of all procedures should have brief comments that describe their functions. These comments do not describe the details (how to implement the function) because the details sometimes change frequently. This avoids unnecessary annotation maintenance and incorrect comments. The details are described by the code itself and the necessary internal comments.
It should be explained when the use of the parameters passed to the process is not obvious, or when the process has requirements for the value range of the parameters. If the procedure changes the return value of functions and variables (especially through parameter references), the return value should also be described at the beginning of the procedure.
The comments at the beginning of the process should contain the following section title. For examples, see the "formatting Code" section below.
Section title comment content
The function of the purpose process (not the way to achieve the function).
Assume that its state affects the list of external variables, controls, or other elements of this process.
A list of the effects of the effect process on each external variable, control, or other element.
Enter an explanation of each parameter for which the purpose is not obvious. Each parameter should occupy a separate line and have its internal comments.
Returns an explanation of the return value.
Keep the following points in mind:
Every important variable declaration should have an internal comment describing the purpose of the variable.
Variables, controls, and procedures should be named clearly, and internal comments are required only when explaining complex details.
An overview describing the Script should be included at the beginning of the Script, listing objects, processes, algorithms, dialog boxes, and other system dependencies. Sometimes it is useful to have a false code that describes the algorithm.
Formatting code
You should reserve as much screen space as possible, but still allow logical structure and nesting to be reflected in code formats. Here are a few tips:
Standard nested blocks should be indented by 4 spaces.
An overview of the process comments should be indented by 1 space.
The top-level statement after an overview comment should be indented by 4 spaces, and each layer of nested blocks should be indented by 4 more spaces. For example:
'*
'Objective: returns the location where the specified user first appeared in the UserList array.
'enter: strUserList (): the list of users you are looking for.
'strTargetUser: the user name to look for.
'returns: the index of strTargetUser when it first appears in the strUserList array.
'if the target user is not found, return-1.
'*
Function intFindUser (strUserList (), strTargetUser)
Dim I 'loop counter.
Dim blnFound 'the mark of the target found.
IntFindUser =-1
I = 0 'initializes the loop counter.
Do While i
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.