Okay, I know that each instance of a class shares all the methods
defined by that class (i.e. any instance can call such a method), and
that each instance gets its own copy of each property that has the
same name (i.e. a property CarColor As Color would be accessible by
an instance of the Car class with Me.CarColor = RGB(255, 0, 0) for
example, and each one has its own value. But what about a static
variable in a method?
Class Car
Public Property CarColor As Color
Sub Car()
CarColor = RGB(0, 0, 0) // cars start out basic black
End Sub
Function StupidVIN() As Integer
Static myUniqueID As Integer = 0
Dim result As Integer
result = myUniqueID
myUniqueID = myUniqueID + 1
Return result
End Function
End Class
...
Dim a, b As Car
a = New Car()
b = New Car()
a.CarColor = RGB(255, 0, 0) // I want mine in red!
MsgBox "a's unique ID: " + CStr(a.StupidVIN())
MsgBox "b's unique ID: " + CStr(b.StupidVIN())
Should both print the same value (because a and b are separate
objects in memory), or a different value (because the static variable
is shared per-method and thus increments itself regardless of whether
called from a or b)?
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>