We often use multi-value parameters in our automation
projects as they are a way to offer options for your end user to select
from. Usually you, as the developer,
will want to limit these options to what’s available, either due to selections
already made or other constraints. In
this post, we’ll describe how to control values for one option based upon
another selection.
Have a look at the User Interface (UI) shown below for a
conveyor design by Salt Automation.
Let’s take a look at how we can accomplish this. We can set the value options for the Duty
Cycle parameter in either the Parameters dialog box via traditional methods or
we can set it via iLogic code, using MultiValue.SetList.
The scheme for the MultiValue.SetList is:
MultiValue.SetList("parameter
name", "value 1", "value
2", "value 3")
In our example, it would look like this:
MultiValue.SetList("Duty_Cycle", "Heavy", "Light")
The benefits to setting the value options in code versus the
traditional method are that you can set the order in which you want them
displayed but more importantly, you modify the value options at run-time
through your code.
Let’s look at how we can modify the value options of our
Motor Selection parameter at run-time.
We’ll do this using the Case structure.
This could also be done with an If Then statement.
Select Case Duty_Cycle
Case "Heavy"
MultiValue.SetList("Motor_Selection",
"7.5 hp", "5 hp")
Case "Light"
MultiValue.SetList("Motor_Selection",
"2 hp", "1 hp")
End Select
The code above will set the Motor Selection options based up
on the selection of the Duty Cycle parameter.
The entire code is listed below. I am also setting the ValueOptions, which
will be covered later.
' Set multi-value options
MultiValue.SetValueOptions(True, DefaultIndex := 0)
MultiValue.SetList("Duty_Cycle",
"Heavy", "Light")
' Set Motor Selection based on Duty Cycle
Select Case Duty_Cycle
Case "Heavy"
MultiValue.SetList("Motor_Selection",
"7.5 hp", "5 hp")
Case "Light"
MultiValue.SetList("Motor_Selection",
"2 hp", "1 hp")
End Select
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” ~ Mosher’s Law of Software Engineering
Thanks,
Randy
I prefer to use Codelobster editor
ReplyDelete