# tip Using Conditions and the Splice Function to Replace "if" Statements

## Recommended Posts

• Seeq Team

We often do calculations where we are interested in having one result if one condition is true and a second result if another condition is true.  In this post we will discuss how to do this calculation in Seeq.

We will create a new single signal which runs different calculations during different periods of time. This technique can be used to replicate "if" logic or "if / else" logic currently being used in excel.

Example existing code from excel or other systems

• IF Temperature > 90 then show a result of  (Temperature * 100)
• IF Temperature < 90F then show a result of  (Temperature + 10)

### Step 1: Identify two modes of operation

• In the Tools tab identify the following conditions using the Value Search tool:

### Step 2: Use formula to reconstruct "if/then statement" using Seeq's Splice Tool

Local Variables:

Name
Item
Type
\$Temperature Temperature Signal
\$HighTempCondition Greater than 90 Condition

Seeq Formula:

```\$HighTempCalc = \$Temperature * 100
\$LowTempCalc = \$Temperature + 10

\$LowTempCalc.splice(\$HighTempCalc,\$HighTempCondition)```

Section 1  -  \$HighTempCalc
This is a local variable which is to be run during periods of high temperature

Section 2  -  \$LowTempCalc
This is a local variable which is to be run when NOT in periods of high temperature

Final  -  \$LowTempCalc.splice(\$HighTempCalc,\$HighTempCondition)
Combine your two series. Use the LowTempCalc series, unless you are in the High Temperature condition, in which case use the HighTempCalc

Content Verified DEC2023
Edited by Rupesh Parbhoo
Updated images, corrected language on local variables in formula.
• 2
##### Share on other sites

• 1 year later...

Why this isn't working?

##### Share on other sites

Hi Ingrid,

you try to use splice on a scalar, which is available since R51. In lesser versions you can apply splice only on signals, so changing \$h to a signal first should resolve the issue:

`\$h.tosignal().splice(\$l, \$lfc)`

Regards,

Thorsten

• 1