Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   NI LabVIEW (http://www.chiefdelphi.com/forums/forumdisplay.php?f=182)
-   -   Paramaterizing Case Statements (http://www.chiefdelphi.com/forums/showthread.php?t=74555)

paulcd2000 15-02-2009 12:13

Paramaterizing Case Statements
 
Hey all, i have a quick question. I know that in C, we could use variables in case statements (e.g. if(time_elapsed<time_to_intercept){...} (where time_to_intercept was calculated earlier in the code)). Is there any way we can do that in Labview?

Thanks!

airnate 15-02-2009 13:58

Re: Paramaterizing Case Statements
 
Yes. And no. (there, that was simple, right?) :p

The problems is that your question is not as simple as it may seem. It really depends on exactly what you are asking.

Yes, you can perform a calculation and wire it to an indicator and then use the indicator's local variable later in the program to read back the value. However, in general, if you can keep your value in a wire (i.e. instead of using local variables), your code will be faster and use less memory.

Note that for the size of the FRC projects, this is really not likely to make a difference in performance, but it's something to keep in mind as you use LabVIEW.

If you are asking if you can actually evaluate expressions as part of the case statement itself, then the answer is no. All of the case expression needs to be evaluated up front prior to the actual case statement.

What you could do is use enumerated types or strings to help make the case statement more legible. If you pass in the enumerated type or string for which you wanted to execute code, the case statement would display text for each case (more like a C switch statement).

EricVanWyk 15-02-2009 14:03

Re: Paramaterizing Case Statements
 
http://zone.ni.com/reference/en-XX/h...ce_structures/

You can use a range for your cases, as described in the page above.

paulcd2000 15-02-2009 14:08

Re: Paramaterizing Case Statements
 
Quote:

Originally Posted by airnate (Post 821310)
Yes. And no. (there, that was simple, right?) :p
...
If you are asking if you can actually evaluate expressions as part of the case statement itself, then the answer is no. All of the case expression needs to be evaluated up front prior to the actual case statement.
...

That was what i wanted to know. Thanks. i'll deal with it by doing the logic outside the case structures and giving the results as booleans.

Greg McKaskle 15-02-2009 15:18

Re: Paramaterizing Case Statements
 
This question seems pretty much wrapped up, but I'll add one thing.

Because of dataflow, writing to a local in one location and reading for the case in another is usually not what you want. The local may well be read immediately, before you code writes to it. Wires don't do that. So to summarize, watch for race conditions and think in parallel when using local or global variables.

Greg McKaskle


All times are GMT -5. The time now is 15:11.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi