+ Reply to Thread
Results 1 to 4 of 4

Thread: A simple timer

  1. #1
    travy92's Avatar
    travy92 is offline Learning Programmer
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    76
    Rep Power
    17

    Post A simple timer

    In this tutorial we'll be making a simple timer that prints off a line every second into a ListBox.
    ----------------------------------------------------------------
    GUI (Layout)
    Here's my GUI (layout):



    ----------------------------------------------------------------
    What you need to add:

    4 Command Buttons:

    With the following names/captions:

    #1 Command Button:
    Name: cmdStart
    Caption: Start Timer

    #2 Command Button:
    Name: cmdStop
    Caption: Stop Timer

    #3 Command Button:
    Name: cmdClear
    Caption: Clear Text

    #4 Command Button:
    Name: cmdExit
    Caption: Exit

    1 ListBox
    With:

    Name:lstCount
    Caption: (None)

    1 Timer
    With:

    Name: tmrTimer
    Caption: (None)

    ----------------------------------------------------------------
    CODE:
    Add this code to General Declarations:
    Dim Response As Integer
    Dim mintCount As Integer
    Then this:

    Private Sub cmdClear_Click()
    lstCount.Clear
    End Sub

    Private Sub cmdExit_Click()
    Response = MsgBox("Exit Program?", vbInformation + vbYesNo, "Are you sure?")
    If Response = vbYes Then
    Unload Me

    ElseIf Response = vbNo Then
    Me.Refresh

    End If

    End Sub

    Private Sub cmdStart_Click()



    mintCount = 0

    Cls

    tmrTimer.Enabled = True



    End Sub



    Private Sub cmdStop_Click()



    tmrTimer.Enabled = False



    End Sub





    Private Sub tmrTimer_Timer()



    mintCount = mintCount + 1

    lstCount.AddItem "Timer fired again. Count = " & mintCount



    End Sub
    ---------------------------------------------------------------
    CODE EXPLANATION:

    Private Sub cmdClear_Click()
    lstCount.Clear
    End Sub
    This just means whenever you click the "Clear Text" button, the ListBox will be cleared of all text.

    ---------------------------------------------------------------
    Private Sub cmdExit_Click()
    Response = MsgBox("Exit Program?", vbInformation + vbYesNo, "Are you sure?")
    If Response = vbYes Then
    Unload Me

    ElseIf Response = vbNo Then
    Me.Refresh

    End If

    End Sub
    What this does is whenever you click the "Exit" button, it asks you if you REALLY want to exit. If YES then it will exit, if NO then it will jsut go back to the previous screen.

    ----------------------------------------------------------------
    Private Sub cmdStart_Click()



    mintCount = 0

    Cls

    tmrTimer.Enabled = True



    End Sub
    This code makes the timer start every time you click the "Start Timer" button.

    ----------------------------------------------------------------
    Private Sub cmdStop_Click()



    tmrTimer.Enabled = False



    End Sub
    Very simple code that stops the timer when you click the "Stop Timer" button.

    ----------------------------------------------------------------
    Private Sub tmrTimer_Timer()



    mintCount = mintCount + 1

    lstCount.AddItem "Timer fired again. Count = " & mintCount



    End Sub
    Ok this is a tad harder then the rest of the codes...
    "mintCount" was dimmed as an integer in the "General declarations" section. With this said, the code means that every time the mintCount function is used, it adds +1 onto itself.

    lstCount.AddItem "Timer fired again. Count = " & mintCount

    Means that every time the mintCount is used, it adds the line "Timer fired again. Count = ?" Into the ListBox.
    (The "?" means the number that the timer is up to)

    ----------------------------------------------------------------

    Well this is the end of my Tutorial. Thanks for taking the time to read my tutorial.



    This tutorial made completely by me, Travy92.
    Special thanks the Tcm9669 for the screenshot program.

    I've enclosed the sample:
    Attached Files Attached Files
    Last edited by Jordan; 09-10-2007 at 06:18 AM.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    don_malko is offline Newbie
    Join Date
    Feb 2008
    Posts
    1
    Rep Power
    0

    Very simple to follow

    Good tutorial.

    Thanks.

  4. #3
    giv3mesmile's Avatar
    giv3mesmile is offline Newbie
    Join Date
    Jan 2010
    Location
    Europe>Balkan>Serbia>Belgrade
    Posts
    14
    Rep Power
    0

    Re: A simple timer

    Uhm how do u save a program , so u can run it in windows?

  5. #4
    kailas is offline Newbie
    Join Date
    Feb 2010
    Posts
    16
    Rep Power
    0

    Re: A simple timer

    Excellent programs. I have it handy. Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 4 users browsing this thread. (0 members and 4 guests)

Similar Threads

  1. How to add timer in SDL?
    By even821 in forum C and C++
    Replies: 3
    Last Post: 10-16-2011, 11:45 PM
  2. help with a timer
    By mitchel0 in forum C# Programming
    Replies: 7
    Last Post: 04-26-2011, 12:33 PM
  3. How to create a simple egg timer
    By Vswe in forum Visual Basic Tutorials
    Replies: 8
    Last Post: 09-19-2010, 05:26 AM
  4. First Timer
    By Hunter100 in forum C and C++
    Replies: 3
    Last Post: 02-07-2010, 07:10 AM
  5. Simple timer
    By im-not-alive in forum Java Help
    Replies: 1
    Last Post: 01-22-2008, 10:57 AM

Tags for this Thread

Bookmarks

Posting Permissions

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