Results 1 to 22 of 22

Thread: timer not firing

  1. #1

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    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

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    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.

  3. #3

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: timer not firing

    Quote Originally Posted by SamOscarBrown View Post
    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

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    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.

  5. #5
    Addicted Member
    Join Date
    Sep 2013
    Posts
    190

    Re: timer not firing

    Are the Call Function and Timer control on separate forms?

  6. #6
    Addicted Member
    Join Date
    Sep 2013
    Posts
    190

    Re: timer not firing

    BTW, I realize people stress using Option Explicit, but I've never used it and have never had any problems.

  7. #7

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: timer not firing

    Quote Originally Posted by SamOscarBrown View Post
    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

  8. #8

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: timer not firing

    Quote Originally Posted by Conroy Vanderbluff View Post
    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

  9. #9

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    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

  10. #10
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    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?

  11. #11

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: timer not firing

    Quote Originally Posted by SamOscarBrown View Post
    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

  12. #12
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    Re: timer not firing

    OK give me a sec....will add that second form and test

  13. #13
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    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.

  14. #14

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: timer not firing

    Quote Originally Posted by SamOscarBrown View Post
    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

  15. #15
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    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.

  16. #16
    Member
    Join Date
    Jan 2014
    Location
    Chennai
    Posts
    35

    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.

  17. #17
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    Re: timer not firing

    Quote Originally Posted by Sethu View Post
    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

  18. #18
    Member
    Join Date
    Jan 2014
    Location
    Chennai
    Posts
    35

    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?

  19. #19
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: timer not firing

    Quote Originally Posted by Sethu View Post
    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  20. #20
    Member
    Join Date
    Jan 2014
    Location
    Chennai
    Posts
    35

    Re: timer not firing

    Quote Originally Posted by techgnome View Post
    but it would have... once at least...-tg
    Yes, I got it...

  21. #21
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    Re: timer not firing

    Quote Originally Posted by Sethu View Post
    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.....

  22. #22
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width