Hey, Thanks Marble Eater,
I just think that its a nice "handshake" making everything explicit what this variable is to do. ByRef is a tad sloppier, because it can work as an in/out parameter not just out. VB can force an out parameter by using a Function or Property Get procedure, so its not impossible to force an out interpretation, but, well, sometimes you want a "regular" parameter to be tagged as out.
As you suggested, I could initialize the variable, sure, to suppress the warning, or I could even just turn that warning off, but the real idea is to enforce the contract. As for the compiler error, its actually just a soft compiler "warning" so its no big deal... but this would not be occurring in C# if using the out keyword.
Even trying again now, I was almost unable to reproduce it, as it seems fine for value types. For example, the following shows no compiler warnings:
Code:
Sub MySub
Dim i As Integer
ReturnInteger(i)
End Sub
Sub ReturnInteger(ByRef out_Integer As Integer)
out_Integer = 10
End Sub
Even with the code commented out, the compiler sees that the i variable is at least passed in somewhere to a ByRef parameter and looks no further. There is no warning on this code.
However, with a reference type, you can get a warning:
Code:
Sub MySub()
Dim c As Class1
ReturnClass1(c)
MessageBox.Show(c.Name)
End Sub
Sub ReturnClass1(ByRef out_Class1 As Class1)
out_Class1 = New Class1
End Sub
Public Class Class1
Public Name As String = "Yoda"
End Class
The above runs 100% fine, of course, but the VB 2005 IDE will place a squigly line under the "c" within the line ReturnClass1(c), with the warning stating:
Variable c is passed by reference before it has been assigned a value. A null reference exception could result at runtime.
Not the biggest deal in the world, at all, but I was previously hoping that VB might recognize the OutAttribute, which upon reading is really only used for COM Interop marshalling. Oh well, maybe VB will add the out keyword some day, theres no reason for them not to...
Thanks for your thoughts here, ME,

,
Mike