SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 9 of 9
  1. #1
    Member
    Join Date
    Feb 2005
    Location
    New York
    Posts
    395
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Total Downloaded
    0

    passing variables between actions

    anyone tried to pass variables between actions? for example of i've defined a variable "variable1" in action "A", can i use pass its value to action "B"?

  2. #2
    Moderator JakeBrake's Avatar
    Join Date
    Dec 2000
    Location
    St. Louis - Year 2025
    Posts
    15,609
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: passing variables between actions

    You have a number of options. Here are a few:
    1. Defined the var outside of the LR script sections, ie.,
    <font color="brown">
    int myVar;

    vuser_init()
    {
    return 0;
    }
    </font>

    2. Force/save to a LR parameter. This parameter is known to all subsequent code and does not need to be forced outside of the section as the above example.

    3. Add an arg inbound to your action section. Pass the arg.

  3. #3
    Member
    Join Date
    Feb 2005
    Location
    New York
    Posts
    395
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Total Downloaded
    0

    Re: passing variables between actions

    thanks Jake, i tried the first option and it worked...awesome! coule you please elaborate more on the other two options, or point me out to a docs, thanks

  4. #4
    Moderator JakeBrake's Avatar
    Join Date
    Dec 2000
    Location
    St. Louis - Year 2025
    Posts
    15,609
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: passing variables between actions

    [ QUOTE ]
    ...could you please elaborate more on the other two options, or point me out to a docs, thanks

    [/ QUOTE ]
    ... or someone else? [img]/images/graemlins/smile.gif[/img] We are a team. [img]/images/graemlins/smile.gif[/img]

  5. #5
    Senior Member
    Join Date
    Dec 2006
    Posts
    1,838
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: passing variables between actions

    Can the variable declared in the init part reused in the action and end section.Hadnt tried that before.
    i am have been used in declaring variables in the same section whenever i code and use it there itself.Same thing i do for the functions.
    Maybe i can give a try for that.

  6. #6
    Moderator JakeBrake's Avatar
    Join Date
    Dec 2000
    Location
    St. Louis - Year 2025
    Posts
    15,609
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: passing variables between actions

    The risk with using option 1 is that one could easily trounce the var elsewhere and introduce code defects. That of course leads to debate about "best coding practices".

  7. #7
    Moderator
    Join Date
    Jan 2006
    Location
    Charlotte, NC
    Posts
    1,600
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: passing variables between actions

    To follow up on what Jake said, and to clarify for kiran...

    When you write:

    int myvar;

    int vuser_init()...

    You are merely creating a regular C global variable. You will probably not have to use an "extern int myvar;" in Action.c because of the way LR compiles scripts.

    As it is a global variable, all the rules and pitfalls of global variables in C apply.

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

    About the second option...

    Use "sprintf" and "lr_save_string" to save a created string into an LR parameter. This can then be used forever afterwards.

    "lr_eval_string" will extract the value into a char* for you. "atoi" can be used to convert this to an integer.
    Unless you are writing a compiler, strtok is NOT the answer.
    See: http://www.sqaforums.com/showflat.ph...=541641#542222

    QAF is still an exercise in self-sufficiency! (Thank JB!)

  8. #8
    Member
    Join Date
    Aug 2002
    Posts
    253
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: passing variables between actions

    To answer your question on elaborating on Jake's three suggestions:

    2. Force to a Parameter: A parameter is just a form of global variable, though it's a little different. These are the parameters you see when you press CTRL+L. They are just as perilous as any other global c var in a sense, though from a practical standpoint, since modifying parameters takes slightly more thought, it might be a little safer.

    3. Pass the arg: In c you can pass arguments from one function (or Action in the case of LR) to another. You would set your variable, then you could do a function call like createAccountNumber(checkDigit). This 'checkDigit' is the _argument_ you are _passing_ to the createAccountNumber function.

    This is pretty important c stuff, so I'd encourage you to try to understand it (the rules can be fairly straight forward, but the implementation can be a pain in the neck).

    If you want more reading for:
    1: Google "global c variables"
    2: Google "passing c arguments"

    Also, to truly be able to know c you must also understand "c pointers". Reading about those three topics will make you a much better informed c programmer.

    Good luck.

  9. #9
    Member
    Join Date
    Feb 2005
    Location
    New York
    Posts
    395
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Total Downloaded
    0

    Re: passing variables between actions

    coreydaj, thank you for your clarification, i studied "C" and i know "C", but i didn't we can use "return" and "passing" variables in LR....

    thank you guys all for your help

 

 

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.71%
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 12:25 PM.

Copyright BetaSoft Inc.