|
-
Feb 3rd, 2014, 02:05 AM
#1
Thread Starter
PowerPoster
timer not firing
From form frmBonus12
frmBonusWin.StartTimer
in calling this sub it does not fire the timer
Public Sub StartTimer()
Timer2.Interval = 1000
Timer2.Enabled = True
End Sub
it does not go to the timer at all
Private Sub Timer2_Timer()
If mTime <= 3 Then
'Timer2.Enabled = True
mTime = mTime + 1
If mTime >= 4 Then
Timer2.Enabled = False
Me.Visible = False
frmCleo.Show
frmCleo.AddBonusWinnings
End If
End If
End Sub
what could cause this ?
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Feb 3rd, 2014, 09:13 AM
#2
Re: timer not firing
1. I am sure it DOES 'fire' your timer. Is the Enabled property of the timer set to False initially? Should be.
2. I see you are not using Option Explicit in your form (or mtime is a global variable)? Step through in Debug mode and watch the value of mtime.
3. Get into the practice of properly indenting your code....helps to read it.
4. AND, if you add this line as the first line in your timer, "Static mTime As Integer", you should see the results you want.
-
Feb 3rd, 2014, 10:00 AM
#3
Thread Starter
PowerPoster
Re: timer not firing
 Originally Posted by SamOscarBrown
1. I am sure it DOES 'fire' your timer. Is the Enabled property of the timer set to False initially? Should be.
2. I see you are not using Option Explicit in your form (or mtime is a global variable)? Step through in Debug mode and watch the value of mtime.
3. Get into the practice of properly indenting your code....helps to read it.
4. AND, if you add this line as the first line in your timer, "Static mTime As Integer", you should see the results you want.
put a break on Public Sub StartTimer stepping thru each line it does not start timer
it steps all the way to end sub without going to the timer
Public Sub StartTimer()
Timer2.Interval = 1000
Timer2.Enabled = True
End Sub
Public Sub StartTimer()
Timer2.Enabled = False<----tried adding this line
Timer2.Interval = 1000
Timer2.Enabled = True
End Sub
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Feb 3rd, 2014, 10:20 AM
#4
Re: timer not firing
Did you add the 'static' declaration like I told you in the above post?
You do not need to add the Enabled=False in your code as long as you have the control set to False in the IDE (recommended).
Static lets you keep the value of mTime.
For example, if mtime is not declared at all (as in your code), each time you Enable the timer, it is set to zero. Hence, it will never get above 1.
By using the static codeword, it 'remembers' what the value of mtime was each time it comes into the timer, hence, it will go from zero to 4 before it accomplishes the things you want to do.
-
Feb 3rd, 2014, 10:26 AM
#5
Addicted Member
Re: timer not firing
Are the Call Function and Timer control on separate forms?
-
Feb 3rd, 2014, 10:29 AM
#6
Addicted Member
Re: timer not firing
BTW, I realize people stress using Option Explicit, but I've never used it and have never had any problems.
-
Feb 3rd, 2014, 10:36 AM
#7
Thread Starter
PowerPoster
Re: timer not firing
 Originally Posted by SamOscarBrown
Did you add the 'static' declaration like I told you in the above post?
You do not need to add the Enabled=False in your code as long as you have the control set to False in the IDE (recommended).
Static lets you keep the value of mTime.
For example, if mtime is not declared at all (as in your code), each time you Enable the timer, it is set to zero. Hence, it will never get above 1.
By using the static codeword, it 'remembers' what the value of mtime was each time it comes into the timer, hence, it will go from zero to 4 before it accomplishes the things you want to do.
Don't need static as mTime is form variable see below
Option Explicit
Dim mTime As Integer
Public Sub StartTimer()
mTime = 0 < added this to make sure
Timer2.Interval = 1000
Timer2.Enabled = True
End Sub
Private Sub Timer2_Timer()<--it never goes to this line
If mTime <= 3 Then
'Timer2.Enabled = True
mTime = mTime + 1
If mTime >= 4 Then
Timer2.Enabled = False
Me.Visible = False
frmCleo.Show
frmCleo.AddBonusWinnings
End If
End If
End Sub
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Feb 3rd, 2014, 10:38 AM
#8
Thread Starter
PowerPoster
Re: timer not firing
 Originally Posted by Conroy Vanderbluff
Are the Call Function and Timer control on separate forms?
No the timer is on the form being called
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Feb 3rd, 2014, 10:51 AM
#9
Thread Starter
PowerPoster
Re: timer not firing
I have tried this:
deleted timer1
put a new timer named it timer2
mTime = 0 < added this to make sure
set the timer to Timer2.Enabled = false before true
closed and opened the ide
rebooted
nothing works what else can I try, even a longshot
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Feb 3rd, 2014, 10:55 AM
#10
Re: timer not firing
Do not know what you are doing wrong.
I copied your code (and commented out the three lines in your second if statement and replaced them with a msgbox)---did as suspected....after 8 seconds, it displayed my messagebox.
I set Timer2.Enabled property in the IDE to False
I put a commandbutton on my form to call StartTimer. What do YOU use to call that function?
-
Feb 3rd, 2014, 11:08 AM
#11
Thread Starter
PowerPoster
Re: timer not firing
 Originally Posted by SamOscarBrown
Do not know what you are doing wrong.
I copied your code (and commented out the three lines in your second if statement and replaced them with a msgbox)---did as suspected....after 8 seconds, it displayed my messagebox.
I set Timer2.Enabled property in the IDE to False
I put a commandbutton on my form to call StartTimer. What do YOU use to call that function?
in the calling form named frmCleoBonus
Load frmBonusWin
Me.Visible = False
frmBonusWin.StartTimer< starts the timer here
frmBonusWin.Show
only thing i can think to do is create a new form and copy all the code-Images
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Feb 3rd, 2014, 11:18 AM
#12
Re: timer not firing
OK give me a sec....will add that second form and test
-
Feb 3rd, 2014, 11:22 AM
#13
Re: timer not firing
Works fine in mine when calling from another form.
Can you post the function in which that code is located on frmCleoBonus? (Commandbutton? What?)
EDIT: And you don't need "Load frmBonusWin", simply SHOWING it will 'load' it.
-
Feb 3rd, 2014, 11:38 AM
#14
Thread Starter
PowerPoster
Re: timer not firing
 Originally Posted by SamOscarBrown
Works fine in mine when calling from another form.
Can you post the function in which that code is located on frmCleoBonus? (Commandbutton? What?)
EDIT: And you don't need "Load frmBonusWin", simply SHOWING it will 'load' it.
in frmCleoBonus:
Public Sub StartBonus()
Dim i As Integer
For i = 1 To miMax_Runs '12 constant
Generate20Numbers 'lot of processing here
Next
If Val(Me.lblRunWin) > 0 Then
gBonusAmountWon = Me.lblRunWin.Caption
Load frmBonusWin
Me.Visible = False
frmBonusWin.StartTimer
frmBonusWin.Show
Else 'no win show this form
Me.Visible = False
frmBonusComplete.Show
frmBonusComplete.StartTimer
End If
End Sub
I have found that loading a form before showing it is faster especially with images
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Feb 3rd, 2014, 11:45 AM
#15
Re: timer not firing
This line would be better if you use Cint or Cdbl instead of Val:
If Val(Me.lblRunWin) > 0 Then
So, if you are calling this Sub (StartBonus) with some sort of clickevent or timer, you have to make sure the 'value' of Me.lblRunWin IS greater than zero, otherwise it is never called and you would never see the other form, let alone run it's timer.
So, if it IS greater than zero (you can check by stepping through), then I would be at a loss why yours does not function, but my almost ID code does.
Sorry. I'm out of suggestions.
-
Feb 3rd, 2014, 12:11 PM
#16
Member
Re: timer not firing
Inappropriate location of End If? Try this 
Private Sub Timer2_Timer()
If mTime <= 3 Then
mTime = mTime + 1
Timer2.Enabled = True
End If
If mTime >= 4 Then
Timer2.Enabled = False
Me.Visible = False
frmCleo.Show
frmCleo.AddBonusWinnings
End If
End Sub
Last edited by Sethu; Feb 3rd, 2014 at 12:19 PM.
-
Feb 3rd, 2014, 12:34 PM
#17
Re: timer not firing
 Originally Posted by Sethu
Inappropriate location of End If? Try this
Private Sub Timer2_Timer()
If mTime <= 3 Then
mTime = mTime + 1
Timer2.Enabled = True
End If
If mTime >= 4 Then
Timer2.Enabled = False
Me.Visible = False
frmCleo.Show
frmCleo.AddBonusWinnings
End If
End Sub
No, not really.....you SURELY don't need the "Timer2.Enabled = True" within the timer itself!
However, the original COULD be simplified like this (but his issue is that he claims it is never truly Enabled from the call on the other form---so THEREIN would lie the reall issue, I believe).
Code:
Private Sub Timer2_Timer()
mTime = mTime + 1 'As OP stated, this variable was declared as global.
If mTime >= 4 Then 'would eliminate the greater than sign, but because it is global to the form, not sure if this timer would be called more than once...OR, if called multiple times, OP should reset mTime to 0
Me.Visible = False
frmCleo.Show
frmCleo.AddBonusWinnings
Timer2.Enabled = False 'I prefer to 'stop' the timer after I do all the things I want it to do.....
End If
End Sub
-
Feb 3rd, 2014, 12:39 PM
#18
Member
Re: timer not firing
Dear Sam,
The point I wanted to state is that the condition >=4 was nested within <=3, so that it never got enabled. The Timer could well be 'restarted' from elsewhere.
Btw, can you please throw some light on what the drawback is in calling the timer within the timer?
-
Feb 3rd, 2014, 12:43 PM
#19
Re: timer not firing
 Originally Posted by Sethu
Dear Sam,
The point I wanted to state is that the condition >=4 was nested within <=3, so that it never got enabled. The Timer could well be 'restarted' from elsewhere.
Btw, can you please throw some light on what the drawback is in calling the timer within the timer?
I thought the same thing... but it would have... once at least... if the counter was 3... it would drop into the first IF... where it was incremented (now 4) ... and it then hits the next IF... where, since it is 4, then it would have gone into it... now after that... yes, you're right, it never would have been activated.
-tg
-
Feb 3rd, 2014, 12:52 PM
#20
Member
Re: timer not firing
 Originally Posted by techgnome
but it would have... once at least...-tg
Yes, I got it...
-
Feb 3rd, 2014, 12:59 PM
#21
Re: timer not firing
 Originally Posted by Sethu
Dear Sam,
The point I wanted to state is that the condition >=4 was nested within <=3, so that it never got enabled. The Timer could well be 'restarted' from elsewhere.
Btw, can you please throw some light on what the drawback is in calling the timer within the timer?
According to OP, this timer IS started elsewhere (a function/sub in another form). So, because mTime is a global FORM variable (if it were Declared in a Module, it should be called mTime, but because it is a FORM variable, it should be called gTime), it IS possible that on that form it is changed to smething somewhere other than in this timer. So, if it was set to less than 4 sometime, when you call the timer in my last posted code, it would increase it by 1 until it reached 4, and then the 'trigger' would happen in the if statement. If it were set (or remained at 4) to 4 or above somewhere else, when the timer is once again called, it would still increase by 1, but then 2 secs later (interval is 2000) it would trigger those commands. A better way of doing things is to use a Static variable within the timer, but OP decided not to do that. So, when this thing is called (from wherever), it will increment mTime by 1, and when it reaches 4 (or better), it will trigger those commands.
Now, your question about enabling it within itself. In order to get to that line (timer2.enabled = true), the timer would have already been enabled, so it is a useless statement. If it were false, it coulld never get to that line.....
-
Feb 3rd, 2014, 01:23 PM
#22
Re: timer not firing
Umm... quesiton... and it's probably a stupid one... but HOW do we/you know the timer isn't firing? Has a breakpoint been set? Are you sure you're workign with the same instance of the form (wouldn't be the first time I've seen issues with a default instance of the form)
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|