Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi im writing a program and i hav a timer set up for a login dialog. this works fin bt whn hav th program going the timer is still running and this is causing a problem cause it keeps kicking me out! any ideas how to fix this?
Peter

I puzzeled as to why you have a timer on a log-in dialouge.
However, in the Timer event just disable the time. Timer1.Enabled = False
Stuart

this is the code im using. its for a school project and i have it setup to give a 20 second time limit, if you dont enter within 20 seconds it will eject you from the program. but my problem is that ven when i have timer1.enabled = false, it still keeps running!!
code:
Private Sub cmdOK_Click()
'check for correct password
If txtPassword = "todd" Then
'this tells the program to turn off the timer if the password = "todd"
Timer1.Enabled = False
MsgBox "Password Accepted", , "Login"
Unload Me
Load frmMain
frmMain.Show
LoginSucceeded = True
Me.Hide
Else
MsgBox "Invalid Password, try again!", , "Login"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
End SubPrivate Sub Timer1_Timer()
'the following command tells the program that if no password is
'entered in 20 seconds to eject the user from the program, and to
'end it
If Timer1.Interval = 20000 Then MsgBox "You have run out of time and now will be ejected from the program"
End
End Sub

I think the problem is in the way you are using the Timer. You set the timer interval at the beginning of you code somewhere, probably in the form load event. When the timer counts down to 0 the Timer1_timer event is triggered.
So all you need in the timer event is:
MsgBox "You have run out of time and now will be ejected from the program", vbCritical Or vbOKOnly, "Your Form Title"
Unload me.No need for an If Then statement.
Do not use End to end a VB programme. End is for debugging purposes only. Use Unload.me
With VB as soon as the last form is unload the programme terminates. You could run into problems later if you use end and there are more than one form loaded. The programme will terminate, but will leave the unloaded forms still in memory.
In the Sub_command_click event put the Unload.Me command after the frmMain.Show event. If this is the only form loaded, Unload.Me will terminate the application before frmMain is loaded and nothing after the unload command will ever get executed.
You have a Me.Hide statement which is superfluous. How can you hide a form that you have just unloaded?
No need for both Load frmMain and frmMain.Show. frmMain.Show implicitly loads the form.
Stuart

![]() |
findstr problem...not fin...
|
Vb help
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |