Cashewz wrote:
In any case, i'm now learning to love setting public variables in a
module for all my child-parent variable needs. ;)
Good for you.
Now, go and slap yourself [hard] around the face a few times and stop
doing this.
"Public Variables in a Module" = "Global variable".
These are Bad.
The Good News:
You can access them from anywhere in your project and set them to any
value you want, whenever you need to.
The Bad news.
You can access them from anywhere in your project and set them to any
value.
As an [artificial] example:
Module Globals
Public MonthAbbrevs As String () = { "Jan", ..., "Dec" }
Public Month as Integer = 2
End Module
Class X
Public Sub New()
Console.Writeline( Me.GetMonthname() ) ' OK
Me.SomeMethod()
Console.Writeline( Me.GetMonthname() ) ' BOOM
End Sub
Private Sub SomeMethod()
Globals.Month = 77
End Sub
Private Function GetMonthname() As String
Return Globals.MonthAbbrevs(Globals.Month - 1)
End Sub
End Class
At the very least, wrap your "globals" in Properties; that way you can
protect against this kind of corruption and, if you /do/ start getting
some odd values appearing unexpectedly, you can pop a breakpoint in the
Property to find out /where/ the dodgy data is coming from - try doing
the same with just a global variable!
Regards,
Phill W.