SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Senior Member
    Join Date
    May 2001
    Location
    Ankh-Morpork
    Posts
    2,882
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: eval within funciton not getting return value

    Looks like maybe some sort of name space problem? If I do this, it works:
    ------------------
    Charles Reace
    charlesDOTreaceATverizonDOTnet

    "Any sufficiently advanced bug is indistinguishable from a feature." -Bruce Brown
    web site | [url=http://www.ebookworm.us/[/url]

    [i]...Sound trumpets! Every trumpet in the host! / Sixty thousand, on these words, sound, so high the mountains sound, and the valleys resound.</i] (The Song of Roland)

  2. #2
    Senior Member
    Join Date
    Mar 2002
    Location
    Irvine, CA 92606 USA
    Posts
    384
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: eval within funciton not getting return value

    public rcxx;
    # make rc a global variable

    public function test ( in command )
    {
    command = "rcxx = " & command;
    eval(command);
    # Nothing to return since "rcxx" is Global ...
    }


    # Try test():

    # This should get Return Code "Zero"
    command = "invoke_application(\"notepad.exe\",\"\",\"\",\"SW _SHOW\");";
    test(command);
    pause(rcxx);

    # This should get Return Code -10001
    command = "invoke_application(\"nottepad.exe\",\"\",\"\",\"S W_SHOW\");";
    test(command);
    pause(rcxx);

    ------------------
    cranem451 - cranem@addendum.com

    [This message has been edited by cranem451 (edited 01-07-2003).]

  3. #3
    Senior Member
    Join Date
    May 2001
    Location
    Ankh-Morpork
    Posts
    2,882
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    eval within funciton not getting return value

    If I do this:
    ...then the return value "rc" gets set as expected. If I do this...
    ...then "rc" never appears to get set. Any idea what I'm missing, or is this just not possible, or what?

    ------------------
    Charles Reace
    charlesDOTreaceATverizonDOTnet

    "Any sufficiently advanced bug is indistinguishable from a feature." -Bruce Brown
    web site | [url=http://www.ebookworm.us/[/url]

    [i]...Sound trumpets! Every trumpet in the host! / Sixty thousand, on these words, sound, so high the mountains sound, and the valleys resound.</i] (The Song of Roland)

  4. #4
    Senior Member
    Join Date
    Mar 2002
    Location
    Bangalore,Kar,Ind
    Posts
    112
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: eval within funciton not getting return value

    There is no need to have return (rc) in the test funtion.

    when return (rc) is used then you are forcing the function to return "" because you are not passing any out parameter in the function all and also there is no assignment statement in the test function. Hence in such a case return of this function is "" and that is what you are seeing in the pause statement. There is no name space problem.

    Also avoid using global variables as much as possible. This is not a good development practice.

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

  5. #5
    Junior Member
    Join Date
    Oct 2002
    Posts
    16
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: eval within funciton not getting return value

    Hi Charles,

    Please post the answer to this if you did find it out. I agree with Nagesh's mail that you don't need the "return(rc)". However, that itself does not seem to be causing the problem. I also agree with cranem's workaround. However, that again does not address the core issue. What is happening is that when you do a rc = test(command) outside your function rc is getting reset. You don't need a public variable to fix this. Please see the sample code below for another workaround :

    public function test2() {
    return(15);
    }

    public function test1(in command, out rc) {

    command = "rc = " & command;
    eval(command);
    }


    static command;

    command = "test2();";
    rc2 = test1(command);

    print("rc is " & rc);
    print("rc2 is " &rc2);

    The output I get is
    "rc is 15
    rc2 is 0
    "

    This is strange behavior, in that rc is behaving like a global variable even though it is in the args for the function test1. Also, I'm not sure why rc is getting reset if you do rc = test1(command). This is why you were having problems. If you had not done this and just called test1(command), you should have got the right results. I agree with you that it seems like a namespace problem. BTW...all this code is in the Main Test. No compiled modules used.

    Please let us know if you find out anything from Mercury regarding this behavior. My apologies if I'm mistaken in the understanding of your code and the other subsequent postings.

    Sudhir

  6. #6
    Senior Member
    Join Date
    May 2001
    Location
    Ankh-Morpork
    Posts
    2,882
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: eval within funciton not getting return value

    This may be my compromise solution, having the return code be static within a compiled module. It seems to work and avoids the use of a global variable.

    ### compiled module "command" ###

    static RESULT;
    public function wrapper(in command)
    {
    command = "RESULT = " & command;
    eval(command);
    return(RESULT);
    }


    ### test script ###

    reload("command",1,1);
    myCommand = "win_exists(\"BOGUS NAME\");";
    rc = wrapper(myCommand);
    pause(rc); # should be -10011

    ------------------
    Charles Reace
    charlesDOTreaceATverizonDOTnet

    "Any sufficiently advanced bug is indistinguishable from a feature." -Bruce Brown
    web site | [url=http://www.ebookworm.us/[/url]

    [i]...Sound trumpets! Every trumpet in the host! / Sixty thousand, on these words, sound, so high the mountains sound, and the valleys resound.</i] (The Song of Roland)

  7. #7
    Junior Member
    Join Date
    Oct 2002
    Posts
    16
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: eval within funciton not getting return value

    Charles,

    The problem was the "out" parameter in the test function. Remove that out. Next, I learnt something new today WinRunner is actually creating a global variable with the returncode name of an eval string. In the example below the returncode is rc5. Note how a global( probably static) variable called rc5 is getting created even though I am not declaring it as global :

    static command;

    public function test2() {
    return(38);
    }

    public function test5(in str) {
    print(str);
    }

    public function test1(in command) {

    command = "rc5 = " &command;
    print(command);
    eval(command);
    } # Note you don't need to return or
    # have an out in your function since
    # rc5 has global scope..strange
    # behavior here

    command = "test2();";

    test1(command);
    test5(rc5); # Correct value of rc5 i.e. 38
    # gets printed.

    This gives me the expected output.

    Regards,
    Sudhir

  8. #8
    Senior Member
    Join Date
    May 2001
    Location
    Ankh-Morpork
    Posts
    2,882
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: eval within funciton not getting return value

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by scm1970:
    Charles,

    The problem was the "out" parameter in the test function. Remove that out. Next, I learnt something new today WinRunner is actually creating a global variable with the returncode name of an eval string. ...
    Regards,
    Sudhir
    <HR></BLOCKQUOTE>

    You're right! In the code in my last message, taking out the static declaration at the start of the compiled module didn't matter, since I wasn't using an out param for it in the function. I'm still a little fuzzy on why, but who cares: I can make it work now without having to declare any global variables!

    Thanks,
    Charles

    ------------------
    Charles Reace
    charlesDOTreaceATverizonDOTnet

    "Any sufficiently advanced bug is indistinguishable from a feature." -Bruce Brown
    web site | [url=http://www.ebookworm.us/[/url]

    [i]...Sound trumpets! Every trumpet in the host! / Sixty thousand, on these words, sound, so high the mountains sound, and the valleys resound.&lt;/i] (The Song of Roland)

  9. #9
    Senior Member
    Join Date
    May 2001
    Location
    Ankh-Morpork
    Posts
    2,882
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: eval within funciton not getting return value

    Thanks, Sudhir.

    At least you confirm I'm not going crazy. I'm thinking that, in a sense, the eval call is acting like it's calling another user function, so any variables are local to it unless they are global variables? As another response suggested, I really want to avoid using global variables, so I'll cogitate awhile and see if a different way to skin this cat comes to mind. (I was toying with coming up with a way to "wrap" certain commands so that I could handle error conditions by simply sending them to this function and let it do all the if/else and switch/case stuff based on return values received.)

    ------------------
    Charles Reace
    charlesDOTreaceATverizonDOTnet

    "Any sufficiently advanced bug is indistinguishable from a feature." -Bruce Brown
    web site | [url=http://www.ebookworm.us/[/url]

    [i]...Sound trumpets! Every trumpet in the host! / Sixty thousand, on these words, sound, so high the mountains sound, and the valleys resound.&lt;/i] (The Song of Roland)

  10. #10
    Senior Member
    Join Date
    Mar 2002
    Location
    Irvine, CA 92606 USA
    Posts
    384
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: eval within funciton not getting return value

    Not sure but this soulds right...

    The "eval" statement should be automaticaly defining the variable "RESULT" as static in the Function (local scope to function).


    ------------------
    cranem451 - cranem@addendum.com

 

 
Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.00%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin 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 03:06 PM.

Copyright BetaSoft Inc.