CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2010
    Posts
    4

    Unhappy Timer function problems

    So i'm trying to disable a timer from counting down to 0 when a label is clicked but i keep running into problems. How could i accomplish this without any errors?

    heres the current code bit.
    Code:
    Private Sub Label4_Click()
    frm_1.Visible = False
    Win.Visible = True
    Win.lbl_amount.Caption = "Congratulations! $100"
    Win.Shape1.Visible = True
    Win.Label1.ForeColor = vbRed
    Timer1.Item.Enabled = False
    
    
    
    End Sub
    I've tried changing it to Timer1.Enabled = False without any luck.
    I'm very new to visual basic so help would be tremendously appreciated, Thanks.

  2. #2
    Join Date
    Mar 2010
    Posts
    4

    Re: Timer function problems

    The error shown is
    Code:
     Compile Error: Argument not Optional

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Timer function problems

    You didn't show your Timer() code, which you need. Here's a sample:

    Code:
    Option Explicit
    ' Add a Timer control to your project.  It will be Timer1
    ' It looks like a stop watch in the IDE.
    Dim OldTime As Date
    Dim newTime As Date
    Dim diff As Long
    
    Private Sub Form_Load()
      OldTime = DateAdd("s", 360, Time) ' Add 360 seconds
      Timer1.Interval = 500
      Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
      newTime = Time
      diff = DateDiff("s", newTime, OldTime)
      Form1.Caption = (diff \ 3600) & ":" & Format((diff \ 60 Mod 60), "00") & ":" & _
            Format((diff - ((diff \ 60) * 60)), "00")
      If diff = 0 Then
        Timer1.Enabled = False
        ' You time is UP!  Do something!
        Beep
      End If
    End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Mar 2010
    Posts
    26

    Re: Timer function problems

    Leave out the "Item" bit

    The Correct code is Timer1.enabled=False

    not Timer1.Item.Enabled=false

    I think this solves your problem

  5. #5
    Join Date
    Mar 2010
    Posts
    4

    Re: Timer function problems

    Quote Originally Posted by TurboBob View Post
    Leave out the "Item" bit

    The Correct code is Timer1.enabled=False

    not Timer1.Item.Enabled=false

    I think this solves your problem

    no i tried Timer1.Enable = false

    also to the comment above this one i'm quoting, i don't quite understand.. maybe if i posted my program through a zip someone could get a better understanding of what i'm trying to do?

  6. #6
    Join Date
    Mar 2010
    Posts
    4

    Re: Timer function problems

    http://www.megaupload.com/?d=IGGJVBWI

    Heres the zipped program, it includes all the forms along with the project.vbp

    on frm_1 try placing timer1.enabled = false under label4_click

    it just doesn't run through for me

  7. #7
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Timer function problems

    Ok, I can tell you why Timer1.Enabled = False does not work.
    For some reason you have set the Index property of your timers to zero. That makes them part of a control array, what you don't want.
    Just examine all your timers' properties and erase the index property. Not just setting the value to zero, but deleting the value, leaving the field empty.
    After That Timer1.Enabled = False will work.

    If you reconsider your programming concept: Why do you want to make 15 individual question forms, when they are all identical. If you think about, you will find that you need only ONE form like your frm_1 with the question and the 4 answer labels. You can fill in the question data and title text before you show the form and thus only ever need one form of this kind.
    Last edited by WoF; March 16th, 2010 at 01:51 PM.

  8. #8
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Timer function problems

    Also if your timer is part of a control array [e.g. has an index value] you simply use the index value as part of the statement

    Code:
    timer1(0).enabled=false
    Of course if you only have one timer there is no reason to have an index value on it.

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

Featured