SPONSORS:






User Tag List

Results 1 to 5 of 5
  1. #1
    Member
    Join Date
    Jan 2001
    Posts
    33
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Global vs. local vars

    Hi all!

    I have a quick question that I just wanted to get a definate answer for, even though I think I suspect the answer.

    If you declare a variable globally, can you override that value by declaring the same variable in a function locally? For instance, see the following kinda-code:
    I would expect the value of sTest in this case to be "Local Value," no?

    Thanks everyone!

    Andrew


    ------------------

  2. #2
    Senior Member
    Join Date
    Jan 2002
    Location
    Des Moines, Iowa
    Posts
    289
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Global vs. local vars

    I would have to try it. I think I will when I get into work. I think that you have declared a global value that you changed within a local function or code. That variable will be as it is set in this function the same value for the next function.

    That is how it works in C, VB, Cobol, etc.. but I haven't tried it in 4Test. It would be fairly easy to set up a test example using that theory and then run it in debug mode watching the contents of the variables as you do.

  3. #3
    Member
    Join Date
    Dec 2001
    Location
    chennai,TN,India
    Posts
    30
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Global vs. local vars

    Yes Andrew..,U r Right
    the Result would be "Local Variable"

    ------------------


    [This message has been edited by rasu123 (edited 01-16-2002).]

  4. #4
    Junior Member
    Join Date
    Sep 2001
    Location
    redwood city, ca
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Global vs. local vars

    Okay just to test to verify the result. But would be a nightmare to trouble the script when local var and global share the same variable name.

    ------------------

  5. #5
    Junior Member
    Join Date
    Dec 2001
    Posts
    23
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Global vs. local vars


    Yes you can. This is clearly mentioned
    in the SilkTest docs.

    It says :
    "If a global and local variable with the same name are in scope (accessible) at the same time, your code can only access the local variable. "

    under "Common scripting problems".

    Not good programming practice though



    ------------------

 

 

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 02:29 PM.

Copyright BetaSoft Inc.