51
Switch/Case
Sometimes you have more than one condition you want to check for. You can do this with several
If/Then statements. The Switch/Case statement provides an easier way to make multiple comparisons:
Integer switch
String switch
switch (intvar)
switch (stringvar)
case intval1
case "stringval1"
statementa statementa
statementb statementb
case intval2
case "stringval2"
statementc statementc
statementd statementd
default default
statemente statemente
statementf statementf
endswitch endswitch
You can use integer or string values with the Switch/Case statement. Based on the value of the
variable, the case block corresponding to that value is executed. Each case block can contain multiple
statements but only one case block is executed.
If the value of the switch variable does not match any of the cases, the default block is executed. The
default block is not required. However, if a default block is used, it must be the last block.
Example of Switch
Lexmark MFPs have a job accounting capability. When this feature is enabled, users must enter an
account number before accessing a profile. For this example, users enter a department number when
using profiles. This example script uses a Switch/Case statement to check the department number.
string CustomSubject
// Use the account number as an integer
int DeptNumber = original.useracct.AsInt()
switch (DeptNumber)
case 35
CustomSubject = "Document from Human Resources"
case 41
CustomSubject = "Document from Legal Department"
case 15
CustomSubject = "Document from Shipping Department"
default
CustomSubject = "Document from FooBar Company"
endswitch
with EmailSMTP
.Server="mailserver.com"
.To="[email protected]"
.From="[email protected]"
.Subject=CustomSubject
.Message="Please read."
.CharacterSet=LDD_SMTPCHARSET_US
.Attachments=original.document
.Go()
endwith