vb.net

porting vb6 app to VS2008 vb.net - make compiler flag unitialized form's private variable as error


I can make the compiler give me an error (Use of variable prior to assignment) with:

private sub Test()
   Dim ord As Order
   Dim ord2 As Order
   ord2 = ord
end sub

but not with:

Friend Class frmReceiving
...

Private mobjOrder As Order 

...

private sub Testing()
   Dim ord2 As Order
   ord2 = mobjOrder 
end sub

How can I make it flag as error?


Solution

  • Your second example is not an error. mobjOrder will be initialized to Nothing. You then assign Nothing to ord2. That's a perfectly legitimate thing to do.