Switch expression for label text

I am trying to use a switch expression to dynamically change the text in a label. The value of ({cntBottling.dsTankData}[“BBTW2”]) is 5, but the expression is returning “BBT: N/A” rather than “BBT: 5W”. Can anyone spot anything incorrect in the way I have built this?

TIA D. Lewis

"BBT: " +
switch(
({cntBottling.dsTankData}[“BBTW2”]),
0,
1,
2,
3,
4,
5,
6,
7,
8,
“N/A”,
“1W”,
“2W”,
“3W”,
“4W”,
“5W”,
“6W”,
“7W”,
“8W”,
“N/A”)

David,

The expression looks fine. I have replicated this setup, and it works fine for me. My guess is that the BBTW2 column in your dataset is a String, instead of a number. You can check this by opening the dsTankData dataset in the dataset viewer (the icon looks like a table with a magnifying glass on it). click on a cell in the BBTW2 column, and the column type will be displayed at the bottom.

Let me know what type it is, and we can investigate this further. If it is a string, make sure that your type is correct in the database.

If for some reason you want to keep the data as a string (if my hunch is correct, that is), you can cast the value to an integer with toInt()

Hope this helps,

Carl:

The column type in the dataset is an integer…

David

Hmm, ok. Could you make sure that the value of the BBTW2 column is 5 in FactoryPMI (maybe its 5 in the PLC, but the designer database traffic isn’t enabled?)

Also, is there only one row in the dsTankData DataSet?

It is actually defined in the db table as a float; in the dataset it is an integer (according to factory pmi). The query is returning data as expected, and there is only one line.

Ok, why don’t you give us a call - I’d like to look at it over GoToMeeting, ifyou don’t mind.

800-266-7798, ask for me.

My bad.

I was looking at the wrong dataset. The tank is defined as a double. When I toInt-ed the value within the switch expression, all is fixed. Thanks and sorry. David

Hey, great!

Glad it is working.