grogg Posted July 5, 2005 Report Share Posted July 5, 2005 I want to write a simple if-else statement in the Formula node in Labview. I want to write if (condition) execute else if (condition) execute else execute end end but the "else if" generates error in statement. Is this way of writing not allowed? /grogg edit: Sorry I guess I should have wrote in the General Section Quote Link to comment
Riceman Posted July 6, 2005 Report Share Posted July 6, 2005 Why don't you simply use a case structure to do what you want? You may create as many cases (for each different condition) as you want, and do your calculations inside each different case. Quote Link to comment
grogg Posted July 6, 2005 Author Report Share Posted July 6, 2005 Why don't you simply use a case structure to do what you want?You may create as many cases (for each different condition) as you want, and do your calculations inside each different case. 5223[/snapback] I have already five cases in a case structure and this if-else statement will just be in one of them. If it is possible to write "else if" i would be much easier than doing another case structure inside the first one. I very new at using labview, maybe there is an easier way. Quote Link to comment
m3nth Posted July 6, 2005 Report Share Posted July 6, 2005 Use a case structure with a numeric, enum, or string feeding the question mark terminal. In LabVIEW, each of your "If" and "Else If" conditions will occupy one case of the case structure. You can also use ".." to handle a range of options, such as "0..3", which would work for values 0, 1, 2 or 3. The regular "Else" is equivalent to the case noted as "Default" in the LabVIEW case structures. This can be a case by itself, or it can be assigned to any other case, so you may want the default case to be the case for value 0, so it would look like "0, Default". Quote Link to comment
m3nth Posted July 6, 2005 Report Share Posted July 6, 2005 Ah... I just noted that you are using a formula node... somewhat different. Can you exit the formula node and use the regular LabVIEW case structure? It seems like you would be able to re-enter the same node or a slightly different one following execution to pick up where you left off. Quote Link to comment
grogg Posted July 6, 2005 Author Report Share Posted July 6, 2005 Ah... I just noted that you are using a formula node... somewhat different. Can you exit the formula node and use the regular LabVIEW case structure? It seems like you would be able to re-enter the same node or a slightly different one following execution to pick up where you left off. 5228[/snapback] The code is somthing like this if (mod(x,y)==0) statement else if (mod(x2,y2)==0) statement else statement end end If I would make a case structure, I would have to make the mod(x,y) outside the structure but I don't know how to do that. I guess I could use the block called formula. Quote Link to comment
m3nth Posted July 6, 2005 Report Share Posted July 6, 2005 Hmmm. I use the quotient/remainder function (Block Diagram > Numeric > Quotion & Remainder) to check for even multiples. Is that what you're trying to do?--or something different? Quote Link to comment
grogg Posted July 6, 2005 Author Report Share Posted July 6, 2005 Hmmm. I use the quotient/remainder function (Block Diagram > Numeric > Quotion & Remainder) to check for even multiples. Is that what you're trying to do?--or something different? 5230[/snapback] Yes, that was what I wanted to do thanks. I think I can fix it now. I just not use to this way of programming. I think I prefer to writing simple if statements, but I guess I will get use to it . Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.