Yes, but you can simply make the static variable a dictionary, and use
the hash value of the Variant( PushButton ) so that you can uniquely
identify "any" PushButton of this subclass.
Something like...
Class MyPushButton Inherits PushButton
Event Action()
Static tPushButtonCounter As New Dictionary
Dim myHash As Variant = me
If tPushButtonCounter.HasKey( myHash.Hash ) Then
tPushButtonCounter.Value( myHash.Hash ) = _
tPushButtonCounter.Value( myHash.Hash ) + 1
Else
tPushButtonCounter.Value( myHash.Hash ) = 1
End if
MsgBox Str( tPushButtonCounter.Value( myHash.Hash ) )
End Event
End Class
This way, you don't have to make it a property, if you don't want and
you can still uniquely identify the different instances of the controls.
Is this useful? I'm not sure, but it does get the job done.
- Ryan Dary
Tim Hare wrote:
> A word of caution regarding static variables. When used in a method in a
> class definition, static variables are global to all instances of that
> class. When used in a method of, say, a window, then they are local to the
> window and act like statics from other languages, retaining their value from
> one call to the next.
>
> It's a subtle distinction, but one that can catch you if you're not aware.
>
> Example:
> Let's say we subclass a push button, and we want to retain a counter of the
> number of times it's been pushed. So in the Action event, we put some code
> to increment a counter. But suppose we have a brain lapse and recall using
> static variables in other situations, so we decide that a static would be
> ideal for this use, as we won't have to define a property in the properties
> list.
>
> static myLocalCount as integer
> myLocalCount= myLocalCount+ 1
> Action() // pass the event forward to the instance
>
> One might expect myLocalCount to be nicely hidden in the action event, just
> like a local variable, but retaining its value from one push to the next.
> What will happen, however, is that all instances of our pushbutton class
> will share the same variable. If we have 3 instances of our button and each
> is pressed once, instead of having 3 instances of myLocalCount, each equal
> to 1, we have one myLocalCount which is equal to 3. Not what we intended.
>
> If you think about it, this functionality makes perfect sense, and can be a
> powerful tool. But if you want a local, private variable that retains its
> value, add a property to the class and make it protected or private in
> scope.
>
> Tim
>
>
>
>> -----Original Message-----
>> From: [EMAIL PROTECTED]
>> [mailto:[EMAIL PROTECTED] Behalf Of
>> Arnaud Nicolet
>> Sent: Tuesday, February 27, 2007 5:02 AM
>> To: REALbasic NUG
>> Subject: Confused about new things in RB
>>
>>
>> Hello,
>>
>> I'm trying to learn RB 2007 (I know well RB 5.5).
>> I don't understand the added things (like static variables, for
>> instance). I tryed searching for files in the "Read me" folder, but
>> they don't speak about that.
>> I would prefer to read a file that covers those new functionalities
>> in realbasic (I probably won't understand a C version).
>>
>> Is there any information about that?
>> _______________________________________________
>> Unsubscribe or switch delivery mode:
>> <http://www.realsoftware.com/support/listmanager/>
>>
>> Search the archives:
>> <http://support.realsoftware.com/listarchives/lists.html>
>>
>> --
>> No virus found in this incoming message.
>> Checked by AVG Free Edition.
>> Version: 7.5.446 / Virus Database: 268.18.3/699 - Release Date:
>> 2/23/2007 1:26 PM
>>
> --
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.5.446 / Virus Database: 268.18.4/703 - Release Date: 2/26/2007
> 2:56 PM
>
> _______________________________________________
> Unsubscribe or switch delivery mode:
> <http://www.realsoftware.com/support/listmanager/>
>
> Search the archives:
> <http://support.realsoftware.com/listarchives/lists.html>
>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>