Forum Discussion

vthomeschoolmom's avatar
vthomeschoolmom
Super Contributor
13 years ago

explicit variable declaration and OPTION EXPLICIT

Back in my active server pages days, it was recommended by MS to always explicitly declare variables despite the lack of strong typing. It affected performance, they say. Is the same true of Test Complete? Is there a documented best practice around this? I am drafting standards, and each standard has a support section...



Thanks



S
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Lane,



    Considering the fact that TC utilizes standard VBScript library provided by the OS, I think that everything applicable for VBScript is relevant for TC as well.

    Besides that, several times I've met with the situation when undeclared variable (quite often it was just a typo of the real variable intended to be used) was used in the script code and some time was spent for debugging to figure out why the variable is empty but do not contain expected value. Considering that test code is quite rarely requires 'near real-time performance', my opinion is that explicit declaration of the variable is preferred coding practice.
  • Duh. I feel a touch dumb now. Of course it uses Windows scripting engine. Thanks. You rock.
  • siriusdg_1's avatar
    siriusdg_1
    New Contributor
    Hi... I am doing some troubleshooting on a test that has recorded code and a few custom vbs libs.  I am having trouble and would like to make sure I have the basics covered, which means I would like to apply OPTION EXPLICIT to the entire test, including all project variables, test variables, and script and called function variables.  In VBS, this is simple... you just type Option Explicit at the top of the main file.  But I can't find any way to do this in TestComplete.  Am I missing something?  Any help very greatly appreciated....



    Thanx!

    David
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi David,



    Likewise in TestComplete - you must open every script unit of the project and add Option Explicit as the first line after 'Useunit xxx' lines (if any).