Computing.Net > Forums > Programming > vb problem

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

vb problem

Reply to Message Icon

Name: peter_green86
Date: March 2, 2004 at 15:47:25 Pacific
OS: Windows XP Professional
CPU/Ram: Celeron Tualatin 1.2GHz/5
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: March 2, 2004 at 16:07:01 Pacific
Reply:

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


0

Response Number 2
Name: peter_green86
Date: March 3, 2004 at 10:28:01 Pacific
Reply:

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 Sub

Private 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


0

Response Number 3
Name: StuartS
Date: March 3, 2004 at 12:08:14 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


findstr problem...not fin... Vb help



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: vb problem

VB Problem in addNew www.computing.net/answers/programming/vb-problem-in-addnew/7183.html

VB problem different language of Window www.computing.net/answers/programming/vb-problem-different-language-of-window/2878.html

VB Problem www.computing.net/answers/programming/vb-problem/3529.html