Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

A simple timer

timer

  • Please log in to reply
5 replies to this topic

#1 travy92

travy92

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 73 posts

Posted 09 September 2007 - 02:30 AM

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):

Posted Image

----------------------------------------------------------------
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.

Posted Image

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

I've enclosed the sample:

Attached Files


  • 1

#2 don_malko

don_malko

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 18 February 2008 - 07:08 AM

Good tutorial.

Thanks.
  • 0

#3 giv3mesmile

giv3mesmile

    CC Newcomer

  • Just Joined
  • PipPip
  • 14 posts

Posted 22 January 2010 - 07:29 AM

Uhm how do u save a program , so u can run it in windows? :)
  • 0

#4 kailas

kailas

    CC Newcomer

  • Just Joined
  • PipPip
  • 15 posts

Posted 15 February 2010 - 07:28 AM

Excellent programs. I have it handy. Thank you.
  • 0

#5 focusedaliu

focusedaliu

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts
  • Programming Language:Java, (Visual) Basic, Visual Basic .NET
  • Learning:Java, (Visual) Basic, Visual Basic .NET

Posted 03 September 2012 - 03:08 AM

Tanx alot
  • 0

#6 VNFox

VNFox

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 648 posts
  • Programming Language:C#, PHP
  • Learning:Assembly

Posted 04 October 2012 - 03:44 PM

Cool thanks +1
  • 0

www.pickmike.com
I don't just develop software. I find solutions to your business needs.






Also tagged with one or more of these keywords: timer

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download