1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to? Logic in functions...

Discussion in 'Support' started by mathewsdw, Jun 17, 2013.

  1. mathewsdw

    Joined:
    May 24, 2010
    Messages:
    855
    Likes Received:
    0
    I found out in another thread that one could place logical statements (if, do while, etc.) into alias definitions, which I didn't know. I would assume, but possibly incorrectly, that one could not do that in function definitions except by executing a batch file via @ExecStr. Am I correct in that assumption?
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,307
    Likes Received:
    39
    There is the @IF function. Be aware, though, that all of its arguments are evaluated -- regardless of whether the test condition is true or false.
     
  3. mathewsdw

    Joined:
    May 24, 2010
    Messages:
    855
    Likes Received:
    0
    Thank you, Charles, I kind of suspected as much, but I was really looking for looping ala "Do While".
     
  4. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,190
    Likes Received:
    11
    Dan, here's an example of using @ExecStr with a DO loop.

    Code:
    function DoLogic=`%@execstr[SetLocal & Set C=0 & Do I=1 to %1 (Set C=%@inc[c]) & Echo C: %C I: %I & EndLocal]`
     
    echo %@DoLogic[500]
    C: 500 I: 501
    
    -Scott
     
  5. mathewsdw

    Joined:
    May 24, 2010
    Messages:
    855
    Likes Received:
    0
    Scott, thank you for both giving me the answer and making me laugh. You effectively did a batch file, you just put it directly into the @ExecStr. Somehow it was in my mind that you could just execute external programs and batch files that way. And looking at the documentation (note Rex) there's not a clue that you can do that (although it certainly doesn't explicitly prohibit either).
     
  6. David Marcus

    Joined:
    Jun 4, 2008
    Messages:
    648
    Likes Received:
    1
    The last example shows it can execute "*dir /a:-d /h /o:-d /f".

    Looks like a typo in the first example. Should be "echo %@execstr[2,ver /r]".
     

Share This Page