Static variables...when to use? 
Author Message
 Static variables...when to use?

You could just ditch the variables and use the tag property of the Apply
button to tell when it is to be disabled.  For example, when it is pressed
on tab A write a value to the tag like

cmdApply.Tag = cmdApply.Tag & "a"

Then when the tab changes (say when you're returning to TabA), check the
string with code something like

blnDisableButton = instr(cmdApply.Tag,"a")
If blnDisableButton then cmdApply.Enabled = False
     --or simplify this by saying--
cmdApply.Enabled = Not(instr(cmdApply.Tag, "a")

This will scale to as many tabs as you might add.  For example if you have
tabs A, B, and C and A and B have encountered an apply button click, the
apply button's tag would contain "ab" and an instr on either tab will return
true signalling you to disable the button...but an instr on Tab C would
return false, and thus the button would not be disabled.

Of course, to simplify coding, you could use the Tab control's current index
instead of "a", "b", etc. and thus modify the above code as follows:

--in cmdApply_click--
cmdApply.Tag = cmdApply.Tag & cstr(ssTab1.TabIndex)

'--in ssTab1_click--
cmdApply.Enabled = Not(instr(cmdApply.Tag, cstr(ssTab1.TabIndex)))

This may be more or less troublesome than your current method, depending on
you're preferences...but it saves juggling around a variable for each tab.

Hope I haven't confused more than I've helped.

Doug

Quote:

>-- I am trying to figure out what would be a good scenario in which to
>employ static variables.  For example, say I have a Tabbed Dialog control
on
>my form and I want to disable the "Apply" command button once it is pressed
>for a certain tab.  So if "Apply" is pressed for TabA, my prgram knows not
>to enable that button again for Tab...it's only enabled for TabB etc... I
>created two variables as integers (one per tab), called TabA and TabB whose
>values change from 1 to 0 once the apply button is pressed for a specific
>tab.  That way I can read the value of this variable whenever the user
>changes tabs to figure out whether or not to enable the Apply cmdbutton.
>Each time the form is reloaded, the TabA and TabB vars get reset back to 0
>and so forth.

>The value of these variables changes once (if at all) per form
>load....should they be static variables?  Is there a performace loss by
>declaring variables with Dim instead of Static?

>Thanks



Fri, 19 Oct 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Static variable not static enough ???

2. How do I declare a static global variable ?

3. Static Class and Variable

4. Declaring variables as Static vs Private/Public -- XML

5. Static variables are not supported...

6. Static variables in VBS?

7. Static Variable (VB)

8. Too many local, non-static variables

9. "Permanently" static variables

10. static variables

11. Would like to get value from local static variable

 

 
Powered by phpBB® Forum Software