Solved

Clear a Static Event

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

786 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