Expression help syntax killing me

having a tough time with the syntax for expressions any good manuals or documents out there would be grateful.
I looked at the ignition manual for the gateway but not very good on expressions.
Do I just follow python syntax?

Also maybe somebody can break this down for me.

switch({Entire Screen.SelectParts.SerialNumberDropdown.selectedStringValue}, “All”, “Similar”, “Exact”, “”, " AND [Serial_Number] LIKE ‘" + {Entire Screen.SelectParts.SerialNumberText.text} + "’", " AND [Serial_Number] = ‘" + {Entire Screen.SelectParts.SerialNumberText.text} + "’", “”)

I know what the {} represents but there are a lot of these ’ and " and lastly “” what do those mean.
I think [] represents a db column called serial_number.

Thanks for any assistance

All this expression is doing is creating a string value. Anything within single or double quotes is a string, that’s all. An empty string such as “” is just a string with nothing in it. In this case the + signs concatenate strings (puts strings together).

The resulting string looks like part the text for a database query. The resulting string is probably meant to be used somewhere else as part of a database query.

How the switch function works is here: inductiveautomation.com/support/ … switch.htm

Here’s how I would lay out this particular switch expression:

switch({Entire Screen.SelectParts.SerialNumberDropdown.selectedStringValue}, "All", "Similar", "Exact", "", " AND [Serial_Number] LIKE '" + {Entire Screen.SelectParts.SerialNumberText.text} + "'", " AND [Serial_Number] = '" + {Entire Screen.SelectParts.SerialNumberText.text} + "'", "" )

Now for the breakdown. Going line by line (Let’s assume that {Entire Screen.SelectParts.SerialNumberText.text}=12345:

The first line is the input. Everything else depends on it.

The second line holds the cases. Basically, it’s a lookup list. case1=“All”, case2=“Similar”, case3=“Exact”

Each line after that are return values, depending on the case results…
[ul]All returns an empty string.
Similar returns AND [Serial Number] LIKE ‘12345’
Exact returns AND [Serial Number]=‘12345’[/ul]

The last line is the default value. This is what gets returned when it can’t find a matching case.

Single and double quotes can get interesting when putting strings together. “abc” and ‘abc’ are both strings that equal abc. So what’s the difference? It’s when you need to have quotes as part of the string. If you use enclose it in double quotes, you can use single quotes as part of the string, and vice versa. So, “‘abc’” equals ‘abc’, and ‘“abc”’ equals “abc”

All the quotes look like they run together here on the forum. I suggest making a dummy expression tag and just playing with it. :slight_smile:

Thanks for the help on that break down.

As for the [serial_number] or really in general [] is this a property binding or a db or either?
if yes how do you find it?

Thanks again

Hello,

Since in your case the [ and ] are within quotes they are just part of a string. In your case [ and ] could be used to mean anything that your application wants it to mean. Looks like your application might be using [ and ] to identify column names for a database. If this is the case then it is a database specific syntax thing. Different databases have different syntax for queries. Doesn’t have anything to do with Ignition.

If [ and ] are not within quotes then they can be part of a tag reference. For example here is how a tag reference looks like in an expression: {[default]H1}

[ and ] can also be used to get data out of a dataset, like so :{Root Container.List.data}[0,“column”]

See here for the expression language syntax: inductiveautomation.com/support/ … ssions.htm

You can find component properties, tags, operators, and functions that you can insert into your expressions from the icons that exist in the top right corner of the expression binding window.

I have attached an image of where to find these.

In this case, the square brackets [] are used to delineate the column name in a MS SQL Server Query: see here