Solved

Clear a Static Event

Posted on 2006-06-30
3
148 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now