Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Timer On Form. Problem Exiting The Form

Posted on 2002-07-23
16
Medium Priority
?
183 Views
Last Modified: 2010-05-02
I have a Form Say (Form3), which has a Timer on it
which executes a large amount of code on each 2 seconds.
There is a command button, (Say Command1) which , on click,
executes some code and closes the form.

My program allways crashes on hitting the command button.,
ie The Timer event does not complete its functions.

1. I have tried putting a  Tactive=true  Tactive=False
   in the timer code.. ie Tactive is Public.
   On Click of the command button i look for Tactive=False (itnever becomes false)
2. Have put DoEvents Everywhere.  NO effect.

???  MY question.

How do i click on Command1 , and have the timer finish it processes, then turn Timer off, and complete the procces.


0
Comment
Question by:turnerrob
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
  • +2
16 Comments
 
LVL 2

Expert Comment

by:vbPhil
ID: 7172931
The below code should disable the timer, so it will not fire before you want it to...  Then manually call the Timer event to execute the code contained within.



Private Sub Command1_click()

  Timer1.Enabled = False
  Call Timer1_Timer()

End Sub


Private Sub Timer1_Timer()

  Static A as Long

  'Doing Something Here for Example

  A = A + 1
  If A > 1000 then
    A = 0
  End If


End Sub
0
 

Author Comment

by:turnerrob
ID: 7172947
vbphil..Appreciate your comment.
I gave this a try., but i seem to still have the problem,
the Timer function does not complete., and a variable does not get the required value.
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 200 total points
ID: 7172954
why don't you disable the button until timer has finished its job?
0
Industry Leaders: 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!

 

Author Comment

by:turnerrob
ID: 7172963
Richie.
Thanks for your comment, This does do the job!!!!
I have put a sleep 1 second, at the end of the timer
The program does not bomb out and all works ok.
The Button flashing on/off is a little distracting!!
Would be nice if there was a less brutal solution.
0
 
LVL 20

Expert Comment

by:hes
ID: 7173006
Try usinbg a global variable let's say
Dim NotNow as boolean

At the top of your timer code set NowNow to True
Set it back to False at the end of the timer code.
In the
Private Sub Command1_click()
If NotNow = True then
  ' Code to let the user know to try again a few seconds
Else
  'Your code and exit
End If
End Sub
0
 

Author Comment

by:turnerrob
ID: 7173019
hes.Appreciate your comment.
I have given this a go., and it did not work.,
somehow when the command button is clicked, thats the end of the timer event!!
0
 
LVL 2

Expert Comment

by:Ber
ID: 7173020
Don't disable the command button...
Instead...
In the command button Add code something like this

Do
If terminate = True Then
    End
End If
Loop

terminate is just a publicly declared boolean
this just loops until the timer has finished...(i.e. until the timer has set the terminate flag to true...

Cheers...
Ber...
0
 

Author Comment

by:turnerrob
ID: 7173023
ritchie. Thanks for your comment.
This idea works, will use this until i have more time to look at timers more carefully

regards turnerrob
0
 

Author Comment

by:turnerrob
ID: 7173032
ber.
I have tried putting a public variable at the beginning and end of the timer event, and using it in the Command1
button.
But it does not seem to work!!, When the command1 is clicked, the timer never gets the variable set to (false)

0
 
LVL 2

Expert Comment

by:Ber
ID: 7173044
In the timer set the terminate variable and then call the sleep function this should work...

something like this...


Private Sub Timer1_Timer()
Dim count As Integer

Do While count < 20000
count = count + 1
Loop
terminate = True
Sleep 1

End Sub

Cheers...
Ber...
0
 

Author Comment

by:turnerrob
ID: 7173068
ber.
Will give your idea a try when i return from a job
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7174080
Not use End!
Using End statement is like to try to stop a car running to 100 mph against a wall.
Thanks for "A" grade.
0
 
LVL 2

Expert Comment

by:Ber
ID: 7175587
Richie at the risk of pointing out the obvious, A wall usually does a good job of stopping a car (as I found out to my expense last year .... I don't recommend trying it though ;)  )

Cheers...
Ber...
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7175776
yes, it does the job but how and at which cost it does is the real problem.
:))
0
 
LVL 2

Expert Comment

by:Ber
ID: 7175941
I was messing around with this earlier using the method I suggested and it had some pretty nasty effects so I suggest that you be careful if you choose to use anything similar

Cheers...
Ber...
0
 
LVL 2

Expert Comment

by:vbPhil
ID: 7177943
I see you have a solution already... but I would throw this in for you anyway.


In the Command1_Click() set a flag variable...

  bCloseWhenFinished = True
  Command1.Enabled = False
  Timer1.Enabled = False
  DoEvents
  Call Timer1_Timer()





In the Timer1_Timer event...

at the end of the proceedure,

  If bCloseWhenFinished = True Then
    Unload Me
  End If



This prevents the user from pressing Command1 Again, Allows the timer code to finish, and then closes the form after that.

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

688 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