I honestly don't know, but I'd be really surprised if static
variables were not instance bound.
If I increment a static variable in one object instance, I would not
likely want it to be increased in all other instances of that object.
The above is standard behaviour for most other languages I can think of.
If you truly want a unique ID for each insance of a given object, I'd
be using .hash or even an MD5 of it's .hash property
- Tom
On 10/01/2007, at 11:55 AM, William Squires wrote:
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>
_______________________________________________
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>