SPONSORS:






User Tag List

Results 1 to 9 of 9
  1. #1
    Senior Member
    Join Date
    Dec 2000
    Location
    NY, NY, USA
    Posts
    165
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IsDefined function

    Hi all;

    Is there a function (not class method) that can test whether a variable is defined? I see the function IsSet; I would need something like IsDefined.

  2. #2
    Senior Member
    Join Date
    Aug 1999
    Location
    MA
    Posts
    129
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: IsDefined function

    Can't think of why you'd want to do this, but you could do this:

    Say you are checking if an integer called iFoo is defined.

    Steven Tyler
    Manager - Performance Engineering

    Kronos Incorporated
    tel: +1 978 947 4219

  3. #3
    Senior Member
    Join Date
    Dec 2000
    Location
    NY, NY, USA
    Posts
    165
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: IsDefined function

    Thanks for your reply; however
    do
    if (iFoo < 7)
    Print (...)
    except
    Print ("not defined")

    gives a "misplaced except" compile errror;

    I have some scripts that use a value set in a global variable and I'd like to test first that the variable is defined.

    My guess is that an untyped variable is not something that can be "caught".

    Jerry

  4. #4
    Senior Member
    Join Date
    Jun 2000
    Location
    Chicago, IL USA
    Posts
    383
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: IsDefined function

    I have needed to do this.

    As styler suggests, you just use the variable in some expression and capture the exception if it does not exist.

    What styler doesn't realize, is that the code he wrote will not COMPILE if "iFoo" is not defined.

    To make the function work for a generic variable (or Object), you need to use the "reference operator".
    (read SilkTest online help on this)

    Sample Code:


    *** A question for other readers ***
    I recently noticed a SilkTest feature that I was not aware of:

    The "ArgListCall" keyword.

    It makes the contortions of the "reference operator" obsolete.
    Does anyone know if this is something new in SilkTest 5.0.3.2 ??
    (I already upgraded all of my copies)


    [This message has been edited by RobKapteyn (edited 01-19-2001).]

    [This message has been edited by RobKapteyn (edited 01-19-2001).]
    Rob Kapteyn, CSTE
    RobKapteyn@gmail.com

  5. #5
    Guest

    Re: IsDefined function

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by styler:
    Can't think of why you'd want to do this, but you could do this:
    <HR></BLOCKQUOTE>

    If you are using the reference opertator "@" to hold the name of a variable, then I could definitely see wanting to make sure that variable exists before referencing it.

    I agree with your solution. Using Do...Except and then checking for the specific ExceptNum for "Variable Undefined" is the way to go with this one.

  6. #6
    Senior Member
    Join Date
    Aug 1999
    Location
    MA
    Posts
    129
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: IsDefined function

    RobKapteyn,
    Thanks for finishing the job. Many times I'm at home (no SilkTest, only family) so I go from memory.

    Also, your other comment, I do know about ArgListCall, it is used heavily in two projects that I inherited. It has been around even in QA Partner 4.x.

    For others:
    Yeah, it does away with the @ tricks.

    However, in the projects I own, it is used in a dummy engine implemented in a "T" file.

    Basically the engine blindly picks off a list of records, matching the calling parameters of ArgListCall.
    e.g.
    The "engine" never checks return states of any function(s) called, big mistake.

    Also, it is data driven from the plan level, with symbols pointing to symbols (e.g. $AddThis = ....) and you have no compile context at the T file level if you have the USE statements correct. Really hard to debug.

    I discourage anyone from doing this in the future, I can cite even more examples of bad behavior if you want, and privately tell you the company that wrote this "engine".

    The idea was to teach non programmers how to use a building block approach to do something, but ended up being a maintenance nightmare.

    I leave it for using the legacy code. I made an architectural split of the project into two, one being this old stuff, and the other half being coding standard based object oriented development. This way bad stuff in the old project can't pollute future progress, and I still get to run several years worth of existing tests.

    This may be another topic altogether, which I'd discuss if there was interest...

    [This message has been edited by styler (edited 01-19-2001).]
    Steven Tyler
    Manager - Performance Engineering

    Kronos Incorporated
    tel: +1 978 947 4219

  7. #7
    Senior Member
    Join Date
    Dec 2000
    Location
    NY, NY, USA
    Posts
    165
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: IsDefined function

    Rob;

    Excuse me for my "newbieness", but I try...
    do
    ClassOf (@("i"))
    Print("variable is defined")
    except
    Print(ExceptData())

    and I get the error "Type mismatch -- Parameter 1 to function ClassOf should be a WINDOW".

    What am I missing?

    Thanks;
    Jerry

  8. #8
    Senior Member
    Join Date
    Jun 2000
    Location
    Chicago, IL USA
    Posts
    383
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: IsDefined function

    Sorry.
    My mistake.
    I originally made that function to see if objects (SilkTest "windows") were defined.

    Change "ClassOf( @(VarName) )" to the following:

    "ANYTYPE junk = @(VarName)"

    The ClassOf() really doesn't perform its usual role -- I picked it to as a means of non-destructively manipulating the varible for the sole purpose of generating the "not-defined" exception.

    I will edit the code in my original posting.

    [This message has been edited by RobKapteyn (edited 01-19-2001).]
    Rob Kapteyn, CSTE
    RobKapteyn@gmail.com

  9. #9
    Senior Member
    Join Date
    Dec 2000
    Location
    NY, NY, USA
    Posts
    165
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: IsDefined function

    Rob;

    Thanks! The "@" is quite an operator; I'm impressed!

    Jerry

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 11:08 AM.

Copyright BetaSoft Inc.