07-01-2013 03:44 PM
Hello,
I am trying to use a case structure to determine the time. If it is 10 am, 11 am, 12 pm, 1 pm, or 2 pm I would like to the output to be true. In order to avoid missing the time completely while the code is running I have added a grace period of 5 seconds on either end (any time between 9:59.55 and 10:00.05 should give me a true value for the 10 am case).
However, the code seems to be running specifically by the name of the case and not the code that that case contains. For example the name of the 10 am case is "100000". When I hard wire 100000 as the input value I get true for the 10 am case. However if I use 100001 as the input value, the code uses the default case.
Attached is my VI.
Best,
HF
Solved! Go to Solution.
07-01-2013 03:58 PM
That is expected. The code in any specific case will not run if the condition is not met first.
Just move the ranges to the condition instead of inside the cases.
07-01-2013 04:07 PM
Ofcourse it does. You format the time without separators, so 10 AM becomes 100000, which is then fed to the case structure. After this selection has been made you're trying to check if it's somewhat close ... well you've already checked, haven't you?
What would be an easy solution is to take that formatted string and turn into a number and set ranges in the case. 95955..100005 and so on.
/Y
07-01-2013 04:26 PM
@Don_Phillips wrote:
That is expected. The code in any specific case will not run if the condition is not met first.
Just move the ranges to the condition instead of inside the cases.
The range condition will not work with strings (try wiring 100000 to the case selector and the 10am case will not run), you must convert to number as Yamaeda suggested.
Ben64
07-01-2013 05:55 PM
Hi Yamaeda,
Thanks for the feed back. I can definitely see how my code is redundant. I am new to labview. How can I convert the time string into a number? Also would I need to put my logic that looks at how close the time in relation to the hour out side the case structure? Can you show me what you mean by setting ranges in the case please?
Best,
HF
07-01-2013 06:37 PM
@HFresearch wrote:
Hi Yamaeda,
Thanks for the feed back. I can definitely see how my code is redundant. I am new to labview. How can I convert the time string into a number? Also would I need to put my logic that looks at how close the time in relation to the hour out side the case structure? Can you show me what you mean by setting ranges in the case please?
Best,
HF
Use the Scan From String vi from the string palette to convert your string to a number.
Ben64