Solved

Clear a Static Event

Posted on 2006-06-30
3
153 Views
Last Modified: 2010-04-07
I am using Excel VBA

Is there any way to clear the static event when you click the Refresh Button?

Any help would greatly be appreciated!

Private Sub Commandbutton28_Click()
Static intCounter As Integer
intCounter = intCounter + 1
MsgBox "Clicked" & " " & intCounter
End Sub

Private Sub cbRefresh_Click()


End Sub
0
Comment
Question by:ca1358
  • 2
3 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17019198
No, because the Static variable is local to the sub in which it is defined.

You would have to make intCounter a module level variable and simply reset it:

Dim intCounter As Integer

Private Sub Commandbutton28_Click()
  intCounter = intCounter + 1
  MsgBox "Clicked" & " " & intCounter
End Sub

Private Sub cbRefresh_Click()
    intCounter = 0
End Sub
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 17019214
Or, if you absolutely have to keep the static variable then you would have to set a flag to indicate the clear:

Dim bClear As Boolean = False

Private Sub Commandbutton28_Click()
  Static intCounter As Integer
  If bClear Then
      intCounter=0
      bClear = False
  End If
  intCounter = intCounter + 1
  MsgBox "Clicked" & " " & intCounter
End Sub

Private Sub cbRefresh_Click()
    bClear = True
End Sub
0
 

Author Comment

by:ca1358
ID: 17019325
Thank you!
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question