Tuesday, October 07, 2008

The Ternary Operator in VB

The Ternary Operator in VB

Similar to C# and JavaScript, we can actually have the powerful ternary operator in VB also. The ternary operator is an elegant way of replacing multi-line if else elseif statement blocks. For example in JavaScript

if (blnIsTrueFalse)
t = 'true'
else
t = 'false'

can be compressed as

t = (blnIsTrueFalse)?'true':'false'.

Quite interestingly there is a lesser known function in VB called IIF which supports this too. The syntax of the function is

IIF(expression, truepart, falsepart).

Unfortunately, VBScript does not support this feature and hence we may need to simulate the IIF function manually by wrapping the if then elseif block using a custom function.

[Imported from Blogdrive]Online Virus Scanners

Online Virus Scanners Virus Scanners are no longer difficult to install, tedious to configure. There are easy to use Online Virus Scanne...