devxlogo

Compact Your Code Using IIF and Switch

Compact Your Code Using IIF and Switch

You can often replace an If…Then…Else block with a more compact IIf function:

 ' returns the max of two valuesmaxValue = IIf(first >= second, _	first, second)

Switch is a rarely used function, yet in many cases it proves rather useful as a substitute for a lengthy If…ElseIf block:

 ' is "x" negative, positive or null?Print Switch(x  0, _	"positive", True, "Null")

Note the last test is True, because the three conditions are mutually exclusive and exhaustive.

devx-admin

Share the Post: