-
I used the iif statement in my code on a post and someone told me that it is much slower than a regular if...then statement what makes it slower it seems like it should be faster because it only has to read one line of code. Any comments are welcome............unless i don't like them:p:D
-
it is slower, because it is a function. It goes something like this:
iif:
1: evaulate boolean expression(param 1)
2: Do a regular if then else statement inside the function(determines whic parameter to return)
3: assign correct return value, and return
4: assign return value to variable.
Also, since the return code, and the 2 possible values can be any type, they have to be variants(something like 22 bytes or mem, plus the actual type)
the code looks something like:
Code:
Private Function iif(expr as Boolean, Opt1 as Variant, Opt2 as Variant) as Varient
If expr Then
iif = Opt1
Else
iif = Opt2
End If
End Function
this is compared to just a regular if..then..else statement. Im sure you can see the difference.
Z.
-
but like megatron said about the select case vs. if..then the differance is so minimal on today's computers it it not even worth mentioning. plus the reason it was writen was so that you can shorten the program by using what the computer already knows (i.e. windows API)
Thanks
Regards
E.P.
-
Select case is just a nicely formatted if.. then.. elseif......
end if statement there isnt any difference between the two, except code form.
-
that is true for the IIf statement also. What is the time differance does any one know( i doubt it is anything over a 1 or 2 miliseconds on a athlon 900 Mhz w/ 327MB RAM:D