Trinary For Classic ASP
Ok So I lied about what the first one would be, but since I'm working with some code that's useing the topic I'm talking about I have examples.
Ok there's no Trianry operator in Classic ASP. For those of you who don't know what I'm talking about it's this kind of syntax that you can find in most bracketed languages. The operator uses two charcters and looks like this " ?: ". It's used like this:
//JavaScript
var sDude = new String("Anakin");
var sMessage = new String();
sMessage = (sDude == "Anakin")?"Jedi":"Sith";
alert(sMessage);
//alerts "Jedi"
But On the server VBScript dosen't have anyoperators like that which I find are quite a line saver in other languages. Trianry has been found in other places VBScript has been used like VBA (Visual Basic for Applications), and when it is supported it look like a function/language construct called IIf.
A work around for this that I've found usefull was to define a function for the trinary operation, or inline if, or immeidate if as it's been called. Like so
'VBScript
'RunAt=Server
Function IIf(varTest, varTrue, varFalse)
If varTest Then IIf = varTrue Else IIf = varFalse
End Function
But be wary children, you must declare each parameter or you'll get an error.
I'll try to only post things that I think are hard to find answers and things that I at least have a solid work around for. Otherwise happy coding.
--muja
Ok there's no Trianry operator in Classic ASP. For those of you who don't know what I'm talking about it's this kind of syntax that you can find in most bracketed languages. The operator uses two charcters and looks like this " ?: ". It's used like this:
//JavaScript
var sDude = new String("Anakin");
var sMessage = new String();
sMessage = (sDude == "Anakin")?"Jedi":"Sith";
alert(sMessage);
//alerts "Jedi"
But On the server VBScript dosen't have anyoperators like that which I find are quite a line saver in other languages. Trianry has been found in other places VBScript has been used like VBA (Visual Basic for Applications), and when it is supported it look like a function/language construct called IIf.
A work around for this that I've found usefull was to define a function for the trinary operation, or inline if, or immeidate if as it's been called. Like so
'VBScript
'RunAt=Server
Function IIf(varTest, varTrue, varFalse)
If varTest Then IIf = varTrue Else IIf = varFalse
End Function
But be wary children, you must declare each parameter or you'll get an error.
I'll try to only post things that I think are hard to find answers and things that I at least have a solid work around for. Otherwise happy coding.
--muja