LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Case Structure

Solved!
Go to solution

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

0 Kudos
Message 1 of 6
(2,605 Views)

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.

 

Screen.png

Message 2 of 6
(2,598 Views)

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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 3 of 6
(2,591 Views)

@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.

 

Screen.png


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

Message 4 of 6
(2,585 Views)

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

0 Kudos
Message 5 of 6
(2,573 Views)
Solution
Accepted by topic author HFresearch

@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

 

UsingCaseStructure.png

Message 6 of 6
(2,562 Views)