Formula node: Else if

I want to use a formula node to make my code smaller.
I'm comparing a sensor value and depending on the value i have 3 options.
At the moment i get the error that labview thinks my 'Else if ' is a variabel instead of a command.
am i doing something wrong? another option is to use a Case-structure but this code is allready in a case so i don't know if this could give trouble.
thanks,
Lars
Attachments:
Formula Node Error.png ‏53 KB

Hi James,
when you want to mix datatypes you go with an 1D array of cluster and unbundle instead of the 2nd IndexArray…
Waiting for Christian to post with 1 compare function using a complex number that makes even your look big and a Rube
My own idea:
Just one comparison…
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome

Similar Messages

  • IF statement in Formula Node

    I have the following statement in a Formula Node in LabVEW 7.1:
    if (x=1) y = 3; else y = 1;
    When running the VI, whatever the value of X is, I obtain Y = 3 !!!!
    Why ???
    Tom

    Try x == 1 (instead of x = 1).
    Using LV8.0
    Don't be afraid to rate a good answer...

  • Can I use a formula node to start the execution of a case structure?

    Hi,
    I am working on editing a VI to make it much easier to understand (for colleagues and non LV users). For one reason or another, the VI's creators did not fully make use of the power of case structures and other structure types. In the application we need it for, the instrument cycles and repeats measurements on several objects. We are interested in measuring the motor currents for several motors in the system. As it stands now, for each sample object's run, there is a separate sub-vi diagram which displays its waveform trace and several indicators such as max current, time at max, etc. That code was contained within a T/F case structure and copied and pasted 20 plus times.... Obviously the vi became extrememly cluttered and needed a huge screen to see. The trigger for the current case structures is an EQUALS comparison between one input (which is the sample object counter; and this part I will likely leave unchanged since it makes a lot of sense already) and a constant which was defined 1 through 20+ for case. 
    I have since made one case structure and 20+ instances of that case and have labeled them (at the top selection box near the detent arrows) "1", "2", 3, etc. I am wondering if I can use a formula node to act as the "trigger" which sets each case structure running? I believe that a simple IF statement should work. Please see a snippet of my attempt at making this in C below.
    For the node, I defined X as the input and Y as the output. The input to the node, X, is connected to the sample object counter. The output, Y, is connected to the case selector of the case structure. My attempt at the code is below:
    int32 y
    For(x == 1)
       y = "1";
     For(x == 2)
       y = "2";
    etc, etc.
    Is that above code snippet correct? Do i need something like "ENDIF" or "end if" at the end? Does "y" have to be defined as "int32" or can it be something else?
    Thanks for the help!

    Is your formula node doing anything else besides what is shown?
    Why don't you just wire the value that is going into it at X directly into the selector of the case structure?
    Attachments:
    Example_VI_BD.png ‏2 KB

  • Parenthesis in formula node

    I'm using the formula node and it appears that parenthesis don't work. Is this correct? What is the order of operations?
    The Formula Node Syntax page in the help is extremely brief and sparse, bordering on useless for anyone that doesn't already now what is going on. Is there a more thorough description of the Syntax anywhere?

    Thanks Dennis,
    The error is just an incorrect calculation.
    I put together a simple node and parenthesis did work. So something else must be amiss. I stripped down my VI and equation and made two formula nodes implementing the same equation with and without parenthesis. One gives an exponential decreasing curve, the other a constant array. Where is the error?
    Attachments:
    parenth_ex.vi ‏49 KB

  • How to change content in the formula node of the current vi

    Actually I want to give formula with array index. 
    My formula p=a[0]-30; But i couldnot give array index in the formula expression..
    Please help me in this issue.

    Muthu92 wrote:
    Thank you for your reply. It is very useful for me.  But i can't give conditional operator in that operator. It is showing error.
    My Test cases
    A[0]+A[1]>150
    A[31]-50 <100.
    If those are your exact statements, then they don't make sense in a formula node.  You have to use them in an if-statement or some other type of control logic.  This mimics text-based programming languages such as C... See here for instructions on formula node syntax: http://zone.ni.com/reference/en-XX/help/371361G-01​/lvhowto/formula_node_syntax/
    For instance, you COULD say something like:
    **In this example, let A[0] == x, A[1] == y, A[31] == z**
    if(x+y>150)
    /* do something if this is true */
    else if(z-50 < 100)
    /* do something else */
    EDIT: 
    It should also be noted that Variable Names MUST be lowercase!! I just discovered this
    EDIT2:
    I stand corrected.  After trying to create an example and digging through the LabVIEW Help, I stumbled across this:
    Differences between the Parser in the Mathematics VIs and the Formula Node
    The parser in the Mathematics VIs supports all elements that Formula Nodes support with the following exceptions:
    Variables—Only a, a0, ..., a9, ... z, z0, ..., z9, are valid.
    Logical, conditional, inequality, equality—?:,, &&, !=, ==, <, >, <=, and >= are not valid.
    Functions—atan2, max, min, mod, pow, rem, and sizeOfDim are not valid. You can use these functions in a Formula Node or use their corresponding LabVIEW functions.
    So it DOES NOT seem like Eval Formula Node can do conditionals like you want.  I would just implement them using a LabVIEW based algorithm after all.  Trying to out smart the formula nodes to avoid simple LabVIEW code is just too much of a hassle
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If someone helped you out, please select their post as the solution and/or give them Kudos!

  • Why do in-line conditiona​l expression​s work in Formula Node but not in 'Eval Formula Node.vi'?

    'Eval Formula Node.vi' and a standard Formula node seem identical in most respects in terms of their functionality, however I'm stumped by the case of inline conditional expressions. 
    I'd like to read in a string in the syntax "(expr)?(expr)expr)" from a text file and recieve the output as a double.
    The subVI seemed like the perfect tool since I was already using it to interpret a number of other calculations within the text file, however in this case the behavior is not as expected.
    Has anyone else ever tried this? is there a different syntax needed between the two tools?
    Are there other features of the Formula Note not replicated by this VI?  (so I can avoid them in future)?
    For simplicity I've attached a little demo of the behavior.
    I am currently working in 2010, which I know is getting on in years.
    If the behavior is improved in later versions, that may be a good excuse to upgrade :-) 
    Thanks,
    Elaine R.
    Attachments:
    Conditional Formula Node demo.vi ‏13 KB

    .aCe. wrote:
    Eval formula Node does not do any conditional expressions as far as I am aware.
    That is right. It's a rather dirty hacked VI library to do some formula evalution and has many limitations in comparison to the Formula Node including no support for conditional operator as well as some others. In addition it can also error on some more complex bracketed expressions.
    It is an old example VI that was never revisited and probably never will be as writing a new one from scratch would be easier. But considering that the Formula Node and Mathscript and other possibilities exist, this is not likely going to happen soon.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Formula Node Calculation Issues

    I'm trying to make an array where the output is defined by the formula 25*(2^x) where x is the input variable, with integer iterations from 0 to 7.  To do this, I made an formula node and put it in a for loop.  Unfortunately the (^) symbol is not working right for the calculation.  I tested it simply with x^2 and this did not work, while having x*x returned the correct values.  Instead of outputting the correct values, it outputs seemingly random integers.  Anyone know why?  I am new to this software so I apologize if this this a common issue but I could not find help anywhere else.
    Solved!
    Go to Solution.

    If you use the numeric primitives rather than a formula node, craziness can be avoided (well, sometimes).
    Lynn

  • Using a x b in formula node

    Hi, I am trying to use the following code snipped in formula node:
     z=(x-2.5)*50;
    if (z>-10.0||z< 10.0) {
    y = 0;
    c=0;}
    else {
    y = 5*x-12.5;
    c=1;}
    x is input (from cRIO) and z, y, c are outputs .
    It doesn't seems to work properly, y, c are always 0.
    How else can I use compound evaluation: -10<z<10 ????
    Thanks,
    Arthur
    Solved!
    Go to Solution.

    replace || with &&
    LV 8.2 at Windows & Linux

  • Changing Output type in Formula Node?

    I looked at some other posts on how to set a formula node output as an array, and am unsure why it is not an array. Here is the text in my node: ("out", "in1", and "in2" are all supposed to be 2D arrays; i is an int)
    int32 out [50][50];
    if (i==0)
    out = in1;
    else
    out = in2;

    Hi,
    you must use something like
    int32 out[50][50];
    int32 j, k;
    if (i==0)
    for (j=0; j<50; j++)
    for(k=0; k<50; k++)
    out[j][k]=in1[j][k];
    else
    for (j=0; j<50; j++)
    for(k=0; k<50; k++)
    out[j][k]=in2[j][k];
    I think this is because formula node must be precompiled before execution of your VI. In your case it doesn't know how to address different array elements of "in1" and "in2" because it doesn't know its sizes before you start your VI. In my example I specify the adresses of array elements by using indecies [j][k].
    In any case it looks like you can't make direct assignment of arrays like "arr1=arr2". You always must assign its elements in a loop like "arr1[i]=arr2[i]".
    Good luck.
    Oleg Chutko.

  • Formula Node variable assignment problems

    I have a formula node with the follwing:
    Inputs:E,X,T,PD,I
    OutputsK,PD
    The statement inside the formula node is:
    if (Eelse if (PD=1) if (E else if (E<=X) ;
    else PK=I, PD=1;
    The logic seems to be working the way I want, the problem is in the last else statement. PK is never assigned the value of I. however, PD is assigned the value of 1. There are no errors indicated.
    The source of the I input is the iteration # of the For loop where this formula node is located.
    Anyone see what I am missing??
    Thanks,
    Mike

    Mike,
    In comparisons, == should be used instead of =. This is a very common mistake, and a reason that forumla nodes should be avoided if possible (except of course for very long formulae that would require a lot of nodes.
    It looks like your code would be better represented with LabVIEW nodes instead of in a formula node (for readability - there is no performance difference.)
    Also, you may wish to reconsider using an Input variable that has the same name as an output variable. Try using PDi and PDo, or PD1 and PD2 instead.
    Good luck.

  • Formula node error: missing left parenthesi​s

    Hi guys
    I am new on labview and i am strugling to right a bit of code.
    I am using formula node and i keep getting the error as above on the title moreover it displays: Error on line 5 is marked by a '#' character: "     for   {# H = 00.00.00 to  H = 06.00".
    I am attaching my file so that if you can give me a hand you could have a brief look.
    Thank you
    Solved!
    Go to Solution.
    Attachments:
    time_look up test.vi ‏14 KB

    Hi inaslab,
    still your formula node doesn't make sense: You still overwrite the value for H in the first FOR statement...
    What you want is either an IF-THEN-ELSE or a SWITCH/CASE construct like "IF (H>=0 AND H<6) THEN...". Right-click the formula node, select help, select formula node syntax !
    And I'm even more convinced a standard LV case structure will be much more reasonable here: just wire H to the selector input...
    Message Edited by GerdW on 10-29-2009 11:29 AM
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Formula node, condition

    I want to use conditional expressions such as
    if () then
    statement
    else
    end if
    in the formula node, but there were error messages "unassigned output".
    I followed Ankita's suggestion to use
    if (x<5)
    y=4;
    z=8;
    else
    y=8;
    z=4;
    but there were same error messages(I tried "end if;" also.).
    Thanks.

    Which version of LabVIEW are you using? Any chance it is earlier than 6.0?
    If so, then Ankita's suggestions probably won't work, because there were major changes in Formula Node behavior. I recall that every variable introduced in pre-6.0 formula nodes had to be explicitly added as either an input terminal or an output terminal on the formula node. Furthermore, those older formula nodes used a different style for conditional syntax. It's all documented in the manuals or help documentation that shipped with your LabVIEW version, whatever that may be.
    More to the point, I suggest that you abandon the formula node for simple conditionals like this and just use a case statement. You can wire your x variable into a less-than node, then wire the output of that into a case statement selector. You can very often avoid formula nodes by using case statements or even the "Select" node on the Comparison palette.
    My two cents,
    John

  • Formula node error: missing left parenthesis

    Im trying to compute a simple function in a formula node, I recieve the following errors:
    Error on line 1 is marked by a '#' character: "X3=sin**#2(2*T);"
    Error on line 1 is marked by a '#' character: "X5=(cos**#(2)(T);"

    Has anyone else noticed the name of this guys VI ?
    Thoric (CLA, CLED, CTD and LabVIEW Champion)

  • Formula Node or problem

    Hi,
    I'm having a problem using the formula node.
    The output variable is always 1, but I notice that if the code was:
    if(N != 1)
    L = 1;
    else
    L = 0;
    The program work ok.
    Thanks,
    Sílvia
    Attachments:
    1.png ‏5 KB
    1.png ‏5 KB

    Your screen shot shows if(N!=1||N!=2).  That is if N is not equal to 1 OR N is not equal to 2.  Well, since N can never be equal to 1 and 2 at the same time, of course the statemenet always evaluates to True.
    If N=0  True OR True = True
    If N=1  False OR True = True
    If N=2  True OR False = True
    If N=3  True OR True = True

  • Generate CRC table with Formula Node

    I want to generate an CRC table by formula Node,but the table which generated is not correct,could someone with experience could help me?
    uInt8 j;
    uInt16 i;
    uInt16 crc, c;
    uInt16 crc_tabccitt[255];
    for (i=0; i<256; i++)
     crc = 0;
     c = ( i) << 8;
     for (j=0; j<8; j++)
        if ( (crc ^ c) & 0x8000 )
            crc = ( crc << 1 ) ^ 0x1021;
        else
            crc = crc << 1;
        c = c << 1;
    crc_tabccitt[i] = crc;

    How is it not correct?
    Post your VI with a description what is wrong and what it should be.

Maybe you are looking for