General syntax rules and guidelines

Relevant for: GUI actions, scripted GUI components, and function libraries

When working with actions, scripted components, or function libraries in the Editor, you should consider the following general VBScript syntax rules and guidelines:

  • Case-sensitivity

    By default, VBScript is not case sensitive and does not differentiate between upper-case and lower-case spelling of words, for example, in variables, object and operation names, or constants.

    For example, the two statements below are identical in VBScript:

    Browser("Advantage Shopping").Page("Advantage Shopping").WebList("categoryListboxContactUs").Select "Headphones"
    browser("advantage shopping").page("advantage shopping").weblist("categorylistboxcontactus").select "headphones"
  • Text strings

    When you enter a value as a text string, you must add quotation marks before and after the string. For example, in the above segment of script, the names of the Web site, Web page, and list box are all text strings surrounded by quotation marks.

    In the following example, only the property name (first argument) is a text string and is in quotation marks. The second argument (the value of the property) is a variable and therefore does not have quotation marks. The third argument (specifying the timeout) is a numeric value, which also does not need quotation marks.

    Browser("Advantage Shopping").Page("Advantage Shopping").WebElement("$1,079.98").WaitProperty "innertext", price, 20
  • Variables

    You can specify variables to store strings, integers, arrays and objects. Using variables helps to make your script more readable and flexible. For details, see Variables.

  • Parentheses

    To achieve the desired result and to avoid errors, it is important that you use parentheses () correctly in your statements. For details, see Parentheses.

  • Indentation

    You can indent or outdent your script to reflect the logical structure and nesting of the statements. For details, see Formatting text.

  • Comments

    You can add comments to your statements using an apostrophe ('), either at the beginning of a separate line, or at the end of a statement. We recommend that you add comments wherever possible, to make your scripts easier to understand and maintain. For details, see Formatting text, and Comments.

  • Spaces

    You can add extra blank spaces to your script to improve clarity. These spaces are ignored by VBScript.

  • Reserved Words

    Certain words are reserved by UFT One or VBScript. You cannot use these words as variables, constants, or procedure names.

    • Reserved words in UFT One include the names of all UFT One test object classes, methods, and properties, as well as F-keys (F1, F2).

    • VBScript reserved words can be found in various online VBScript guides.

    For example, a run error occurs if you try to run either of the following statements, which use a test object class name as a variable:

    Set Window = Window("Calculator")


    WinButton = Window("Calculator").GetROProperty("hwnd")

    A run error also occurs when running the following statement because it uses a reserved F-key as a variable:

    Set F1 = createobject("Scripting.FileSystemObject")