Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dani Vainstein1 VBScript Session 8. Dani Vainstein2 What we learn last session? VBScript procedures. Sub procedures. Function Procedures. Getting data.

Similar presentations


Presentation on theme: "Dani Vainstein1 VBScript Session 8. Dani Vainstein2 What we learn last session? VBScript procedures. Sub procedures. Function Procedures. Getting data."— Presentation transcript:

1 Dani Vainstein1 VBScript Session 8

2 Dani Vainstein2 What we learn last session? VBScript procedures. Sub procedures. Function Procedures. Getting data into and out of procedures Call statement. Using arguments ByVal and ByRef.

3 Dani Vainstein3 Subjects for session 8 VBScript coding conventions Constant naming conventions. Variable naming conventions. Descriptive variable and procedure names. Object naming conventions. Code commenting conventions. Functions header conventions.

4 Dani Vainstein4 VBScript Coding Conventions Coding conventions are suggestions are designed to help you write code using Microsoft Visual Basic Scripting Edition. Coding conventions can include the following: Naming conventions for objects, variables, and procedures. Commenting conventions. Text formatting and indenting guidelines. 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 clear, precise, and readable source code that is consistent with other language conventions and is intuitive.

5 Dani Vainstein5 VBScript Coding Conventions Constant Naming Conventions Earlier versions of VBScript had no mechanism for creating user- defined constants. Constants, if used, were implemented as variables and distinguished from other variables using all uppercase characters. Multiple words were separated using the underscore (_) character. For example: USER_LIST_MAX NEW_LINE you can create true constants using the Const statement. This convention uses a mixed-case format in which constant names have a "con" prefix. For example: conYourOwnConstant

6 Dani Vainstein6 VBScript Coding Conventions Variable Naming Conventions To enhance readability and consistency, use the following prefixes with descriptive names for variables in your VBScript code. ExamplePrefixSubtype blnFound, bFoundbln, bBoolean bytRasterDatabytByte dtmStartdtmDate (Time) dblTolerancedblDouble strFirstNamestrString iQuantity, intQuantityi, intInteger lngDistancelngLong objCurrentobjObject sngAveragesngSingle

7 Dani Vainstein7 Descriptive Variable and Procedure Names The body of a variable or procedure name should use mixed case and should be as descriptive as necessary. 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.

8 Dani Vainstein8 VBScript Coding Conventions Object Naming Conventions PrefixSubtypePrefixSubtype linLinepnl3D Panel fraFramechkCheck box hsbHorizontal scroll barcboCombo box vsbVertical scroll barcmdCommand button winWindowbtnRadio button shtSheet Object (Excel)dlgCommon dialog jJava ObjectsimgImage tbrTool BarlblLabel arrArrayslstList box fldFolderspnSpin fleFiletxtText box drvDrivesldSlider txsTextStream (FSO)rstRecordset object dicDictionary xlsExcel application object cnxConnetion object

9 Dani Vainstein9 VBScript Coding Conventions Code Commenting Conventions All procedures should begin with a brief comment describing what they do. 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, 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. Return values for functions and variables that are changed by a procedure, especially through reference arguments, should also be described at the beginning of each procedure.

10 Dani Vainstein10 VBScript Coding Conventions Function Header Module Name: Propose : Author: Date: 23-Mar-2004 Modifications: # By, Date: Description: Input Params: [ ] - [ ] - Return Values: If the function success it returns… If the function fails it returns… Remarks: Syntax:

11 Make sure to visit us Tutorials Articles Projects And much more www.AdvancedQTP.com 11


Download ppt "Dani Vainstein1 VBScript Session 8. Dani Vainstein2 What we learn last session? VBScript procedures. Sub procedures. Function Procedures. Getting data."

Similar presentations


Ads by Google