Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Clear a Static Event

Posted on 2006-06-30
3
Medium Priority
?
158 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

885 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