Lost Password?


  #1 (permalink)  
Old 09-09-2007, 06:30 AM
travy92's Avatar   
travy92 travy92 is offline
Learning Programmer
 
Join Date: Sep 2007
Location: Australia
Age: 15
Posts: 72
Credits: 14
Rep Power: 5
travy92 is on a distinguished road
Send a message via MSN to travy92
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:
Quote:
Dim Response As Integer
Dim mintCount As Integer
Then this:

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

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

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

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

----------------------------------------------------------------
Quote:
Private Sub cmdStop_Click()



tmrTimer.Enabled = False



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

----------------------------------------------------------------
Quote:
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 To view attachments in this forum your post count must be 1 or greater. You currently have 0 posts.

Last edited by Jordan; 09-10-2007 at 09:18 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 02-18-2008, 10:08 AM
don_malko don_malko is offline
Newbie
 
Join Date: Feb 2008
Posts: 1
Credits: 0
Rep Power: 0
don_malko is on a distinguished road
Default Very simple to follow

Good tutorial.

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Timer for splash screen verion24 Visual Basic Programming 3 08-01-2007 02:09 AM
Simple counter Jaan PHP Tutorials 4 05-16-2007 02:56 PM
Project for a simple password cracker waf Visual Basic Programming 2 03-22-2007 05:19 PM
Timer component not working in Service Application smith C# Programming 5 11-28-2006 09:22 AM
Problem adding timer in a text box Viper Managed C++ 6 09-24-2006 09:21 PM


All times are GMT -5. The time now is 03:23 AM.

Contest Stats

WingedPanther ........ 2630.54
Xav ........ 2576.41
Brandon W ........ 1697.27
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 959.05
dcs ........ 646.09
Steve.L ........ 475.59
orjan ........ 407.96
chili5 ........ 378.6

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 97%

Ads