Finally, you shouldn't be using IIf in VB 2008 at all anyway. You should be using the new If operator.
Didn't even know about it. One of those VB6 back lashes. Thanks for pointing it out, that is VERY helpful.
The primary reason i don't like the option strict is in the typeless reference passing. I'm so used to Pointer based languages (languages that don't have as much compiler type checking and leave the onus of that burden on the programmer) that many times i need to return a reference in a reference passed object, but the return will be "nothing" or Nil as it were in Pascal.
thus:
Sub Free(ByRef O as Object)
O = Nothing
GC.Collect
end Sub
There are several times where the "garbage collector" isn't fast enough to remove certain references that pertain to open files or marshalled COM objects, and the only way to get rid of them is via a forced garbage collection. The above may cause a run-time error, but that is on me...not the compiler. It is specifically designed to "NULL" a referenced variable, but the option strict complains when I do this:
dim MyObj as New SomeOtherObject()
MyObj.DoSomething
Free(MyObj)
I Can't type cast the MyObj because VB doesn't type cast, it has "conversion functions" so the function result cannot be reference passed.
I will look into other ways to achieve this, unless of course there is a way to determine at run time if an object is a reference type, then I could do something like this:
<System.Runtime.CompilerServices.Extension()> _
public Sub Free(Of T)(byref item as T)
item = nothing
GC.Collect
end sub
But I think that might cause a glitch if I tried it with an integer.
it furthermore complains about the ByRef types with regards to Excel Automated classes, because the ByRef type is Object, but the passed type is String for a filename, and I can't disable the strict simply for a single object, i have to do it for the whole file.
Also, there is that pesky annoyance with Enumerated types. It seems perfectly capable of thinking of the type as an Integer in memory, but the compiler doesn't think so.
Enum TempEnum
enumVal1
enumVal2
enumVal3
enumVal4
end Enum
dim x as TempEnum = TempEnum.enumVal1
x += 1
Now that works, without a hitch, but option strict won't even let me use the += operator on an enum even though an enum is effectively an integer unless otherwise typed, and I even when forcibly typed on declaration the integer operations aren't. VB is too type specific for my tastes...but then again, I learned on Voids and Pointers in structured programming, and picked up OOP after... I prefer handling types myself because I type cast quite a bit in many languages, and have had to deal with the typed bounds of VB.
I should not have to do:
dim x as tempEnum
x = CType(Ctype(x, Integer) + 1, tempenum)
just to increment an integer aligned enumerated type. *Shrug*
The difference is I expect the run time errors and compensate for them. If option strict off causes the compiler to do extra type checking, slowing down the process, then that's bad. I expect to know my types and to my type checking myself.
I use the TypeOf operator constantly because I'm in charge of types...which allows me more freedom, that obviously VB doesn't want me to have (*chuckle*).
I play around with it...maybe some files I'll turn it off, and others I won't...*shrug*
end sub
I'll play around with it, see what I can work out.
Thanks