From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert the temperature to either Celsius or Fahrenheit using a case structure

Hello NI Labview community,

I need help to convert the temp to either Celsius or Fahrenheit. The VI code should include a case structure,  string subset, number to fractional string, and fractional number to string converter. 

For example, the user enters 24.0C the program converts it to  Fahrenheit and if the user enters 75F it should convert that to Celsius and display the result.

The front panel should look like this. 

jason888_0-1595954746403.png

 

0 Kudos
Message 1 of 8
(2,950 Views)

This sounds like homework.

 

Have you started programming it yourself?

Where are you stuck?

0 Kudos
Message 2 of 8
(2,943 Views)

I'm stuck with how to connect the input string to the function node and display the result with the text. 

 

jason888_1-1595958227534.png

 

0 Kudos
Message 3 of 8
(2,913 Views)

Using string subset will be very limiting. You will only be able to enter temperatures that are 4 characters long. I would use something like "match pattern" instead. You can even find how many places are past the decimal point and make the output temperature have the same precision as the input temperature. 

 

However there is a bug, when I enter in -40 F or C it doesn't perform a conversion, it just outputs -40 again. Can you figure out why? 🙂

 

Capture.PNG

0 Kudos
Message 4 of 8
(2,912 Views)

@jason888 wrote:

I'm stuck with how to connect the input string to the function node and display the result with the text. 

 

jason888_1-1595958227534.png

 


Read the help documentation. (Ctrl+h) will bring up the hover window, then you can click for more detailed help. You will find that the variable "F" does not belong in an expression node.

0 Kudos
Message 5 of 8
(2,908 Views)

@Gregory wrote:
Read the help documentation. (Ctrl+h) will bring up the hover window, then you can click for more detailed help. You will find that the variable "F" does not belong in an expression node.

Actually, almost any character will work, including uppercase F. 😄

 

altenbach_0-1595960313086.png

 

There is an almost unlimited possibility for variables, with the only restriction that it cannot be "pi" and there cannot be more than one variable name per node. Even the following works fine.

 

altenbach_0-1595960510015.png

 

 

Message 6 of 8
(2,894 Views)

If you can assume that the input is well formed (no extra characters or spaces), You could do the following (It would be easy to expand the output format to include more text):

 

altenbach_0-1595961286802.png

(Also make a default case that outputs NaN for unexpected inputs)

 

0 Kudos
Message 7 of 8
(2,880 Views)

@altenbach wrote:

@Gregory wrote:
Read the help documentation. (Ctrl+h) will bring up the hover window, then you can click for more detailed help. You will find that the variable "F" does not belong in an expression node.

Actually, almost any character will work, including uppercase F. 😄

 


Oh man, I've got a whole omelette on my face. Thanks for pointing this out!

0 Kudos
Message 8 of 8
(2,876 Views)