How do you rename a variable based on its content?

Happy Friday,

I have a simple psychrometer app that reads data upon initializing. The data grabbed is in Imperial (U.S.) format. There are currently 2 buttons that allow the user to select Imperial or Metric. Selecting Imperial does not change anything (except returning you from Metric) but selecting Metric converts Fahrenheit to Celsius and inches of mercury to mm of mercury.

I plan on doing calculations in the app to create additional data points and these calculations vary based on whether the input data is Metric of Imperial. I currently have three labels (Pressure_Label, Humidity_Label, and Pressure_Label) that contain three core data points. Humidity, being a percentage of a universal value doesn't change I need to either create two pressure labels and two temperature labels with different names based on the values they contain or have the label name change based on the format (i.e. Pressure_C_Label and pressure_F_Label).

Would someone be so kind as to throw me a bone and/or suggest a block combination to accomplish this. Again, I believe I am over-thinking the process and making life difficult through complexity.

mmm, again I'm not sure to understand what you want to achieve and why yo need different labels..

If you need to know which is the current system selected, then use a new variable to store which is the selected system. I have added a third button in this example only to show you how you can use that new variable to execute different actions regarding the selected system.

Hi, Ramon

Thank you for that extra block. It has given me the ideas I need to create the variables I seek. I will play with it later today and see what I come up with.

1 Like

OK, I spoke too soon. I think your block code does what mine does, but differently. If yours is more versatile, would you please elaborate? What I want to have available (somewhere) at all times is the pressure in both PSI and KPA and the temperature in both Celsius and Fahrenheit., updated by the app in real time, so not static data. As the humidity stays the same, I can use the one reading. I guess I am lost with the make a list command that you are using. Am I creating an open-ended list of possible variables . . . probably not;(. It looks like your blocks also just store only Imperial or Metric but not both. If I am wrong, please explain it to me like you might to a grade-school student. I appreciate your help and I feel I am close to what I want to achieve but not quite.

You're right.

Instead of having two buttons, I'd just use one which will fetch the data for both. Assuming you're storing the values in metric:

1 Like

Yes, I'm storing only the received data (temp, humidity, pressure in Imperial system) in the variables. And then, depending on the button clicked it is shown Imperial or Metric values. Why I am not storing both (3 values for imperial and 3 values for metric)? Because I can convert to Metric from the original data (stored in variables) ...but you can use other 3 variables for metric, convert de data to metric system, and then use the 3 variables with imperial data for one button and the other 3 with metric data for the other.

Other option, like @NishyanthKumar has pointed you is to display always both systems.

Anyway, each time you receive new data you need to store it in the variables.

Regarding to the "make a list" blocks, I have copied it from your shared blocks...I assume that those are the correct blocks you are using to recover your data from the received info.

1 Like