please dont rip this site
Microsoft® Visual Basic® Scripting Edition
VBScript Coding Conventions
Using VBScript |
Previous |

 

What Are Coding Conventions?
Coding conventions are suggestions that may help you write code using Microsoft Visual Basic Scripting Edition. Coding conventions can include the following: The main reason for using a consistent set of coding conventions is to standardize the structure and coding style of a script or set of scripts so that you and others can easily read and understand the code.

Using good coding conventions results in precise, readable, and unambiguous source code that is consistent with other language conventions and as intuitive as possible.

Constant Naming Conventions
Constant names should be uppercase with underscores (_) between words. For example:


 USER_LIST_MAX
 NEW_LINE

Variable Naming Conventions
For purposes of readability and consistency, use the prefixes listed in the following table, along with descriptive names for variables in your VBScript code.

Subtype 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 always be defined with the smallest scope possible. VBScript variables can have the following scope.

Scope Where Variable Is Declared Visibility
Procedure-level Event, Function, or Sub procedure Visible in the procedure in which it is declared.
Script-level HEAD section of an HTML page, outside any procedure Visible in every procedure in the script.
Variable Scope Prefixes
As script size grows, so does the value of being able to quickly differentiate the scope of variables. A one-letter scope prefix preceding the type prefix provides this, without unduly increasing the size of variable names.

Scope Prefix Example
Procedure-level None dblVelocity
Script-level s sblnCalcInProgress
Descriptive Variable and Procedure Names
The body of a variable or procedure name should use mixed case and should be as complete as necessary to describe its purpose. In addition, procedure names should begin with a verb, such as InitNameArray or CloseDialog.

For frequently used or long terms, standard abbreviations are recommended to help keep name length reasonable. In general, variable names greater than 32 characters can be difficult to read.

When using abbreviations, make sure they are consistent throughout the entire script. For example, randomly switching between Cnt and Count within a script or set of scripts may lead to confusion.

Object Naming Conventions
The following table lists recommended conventions for the various objects you may encounter while programming VBScript.

Object type Prefix Example
3D Panel pnl pnlGroup
Animated button ani aniMailBox
Check box chk chkReadOnly
Combo box, drop-down list box cbo cboEnglish
Command button cmd cmdExit
Common dialog dlg dlgFileOpen
Frame fra fraLanguage
Horizontal scroll bar hsb hsbVolume
Image img imgIcon
Label lbl lblHelpMessage
Line lin linVertical
List Box lst lstPolicyCodes
Spin spn spnPages
Text box txt txtLastName
Vertical scroll bar vsb vsbRate
Slider sld sldScale
Code Commenting Conventions
All procedures should begin with a brief comment describing what they do. This description should not describe the implementation details (how it does it) because these often change over time, resulting in unnecessary comment maintenance work, or worse yet, erroneous comments. The code itself and any necessary inline comments describe the implementation.

Arguments passed to a procedure should be described when their purpose is not obvious and when the procedure expects the arguments to be in a specific range. Function return values and other variables that are changed by the procedure, especially through reference arguments, should also be described at the beginning of each procedure.

Procedure header comments should include the following section headings. For examples, see the section "Formatting Your Code" that follows.

Section Heading Comment Contents
Purpose What the procedure does (not how).
Assumptions List of any external variable, control, or other element whose state affects this procedure.
Effects List of the procedure's effect on each external variable, control, or other element.
Inputs Explanation of each argument that isn't obvious. Each argument should be on a separate line with inline comments.
Return Values Explanation of the value returned.
Remember the following points:
Formatting Your Code
Screen space should be conserved as much as possible, while still allowing code formatting to reflect logic structure and nesting. Here are a few pointers:

 '*********************************************************
 ' Purpose:  Locates the first occurrence of a specified user 
 '           in the UserList array.
 ' Inputs:   strUserList():   the list of users to be searched.
 '           strTargetUser:   the name of the user to search for.
 ' Returns:  The index of the first occurrence of the strTargetUser 
 '           in the strUserList array. 
 '           If the target user is not found, return -1.
 '*********************************************************

 Function intFindUser (strUserList(), strTargetUser)
     Dim i                      ' Loop counter.
     Dim blnFound	        ' Target found flag.
     intFindUser = -1
     i = 0                      ' Initialize loop counter 
     Do While i <= Ubound(strUserList) and Not blnFound
         If strUserList(i) = strTargetUser Then 
             blnFound = True    ' Set flag to True
             intFindUser = i    ' Set return value to loop count
         End If
         i = i + 1              ' Increment loop counter
     Loop
 End Function


© 1996 by Microsoft Corporation.
file: /Techref/language/asp/vbs/vbscript/1.htm, 15KB, , updated: 1996/11/22 10:12, local time: 2024/12/24 22:43,
TOP NEW HELP FIND: 
52.15.111.109:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://linistepper.com/Techref/language/asp/vbs/vbscript/1.htm"> Coding Conventions - Microsoft&#174; Visual Basic&#174; Scripting Edition</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?