|
-
May 3rd, 2005, 03:24 PM
#1
Thread Starter
New Member
Timer- Newbie
Hey people wasnt to sure where to post this
I need some help with makin a counter/timer and I'm using vb 6.0
It needs to have a menu with 3 different times intervals to choose from: 1/10th Second, 1 Second
and 10 Seconds. A count up button and a count down button.And a text box which will be the display. The count up and count down buttons need to work so that it counts down or up from what ever is in the display at the time. I think i can manage to do the stop and reset buttons if i figure out the rest but iam sooo stuck...cant see how i can get it all working together!
Anyhelp would be really useful sorry if this is a bit much xxx
-
May 3rd, 2005, 03:32 PM
#2
Re: Timer- Newbie
Welcome to VBF, coralie!
What you need is an ordinary Timer control and a button perhaps.
To control Timer's interval use this:
VB Code:
'you may use menu item to set each interval or perhaps buttons or textbox ...
Timer1.Interval = 100 '1/10 th of second
Timer1.Interval = 1000 '1 second
Timer1.Interval = 10000 '10 seconds
'to reset timer use this:
Private Sub Command1_Click()
Timer1.Enabled = Not Timer1.Enabled
End Sub
-
May 3rd, 2005, 03:39 PM
#3
Fanatic Member
Re: Timer- Newbie
to reset make the label (or whatever you are using to display the timer count) = 0.
for the menu enter the menu editor and make a menu. (uncheck "Visible" if you want a popup menu)
Here is sample code to display the menu (if its a popup menu)
VB Code:
Private Sub Label1_mousedown()
If button = vbRightButton Then
PopupMenu MENU NAME, vbPopupMenuRightButton
End If
End Sub
Hope this helped...
-Sir Loin
-
May 3rd, 2005, 04:39 PM
#4
-
May 3rd, 2005, 06:22 PM
#5
Thread Starter
New Member
Re: Timer- Newbie
Hey People thanx for the replies but i'am still a bit stuck coz ive beed asked specifically for two command buttons on it..one counting up and one counting down, cant even get it to count up at the mo lol. I'm really new to this and my tutor z its fairly simple but wont give us ne help..just have to figure it out for our selves! hmm.
-
May 3rd, 2005, 06:24 PM
#6
-
May 3rd, 2005, 07:10 PM
#7
Re: Timer- Newbie
The main code to count either up or down should be in the Timer event right? You should only have two buttons where you instruct the timer to either count up or down. If this is the case simply declare a variable in the General Declaration section of your form. You could, for example, name it blnCountDown and declare it as a boolean. Then in the cmdCountUp command button (if that is what you're going to call it) simply set this variable to False and in the cmdCountDown command button set it to True. Now all you have to do is to check its value in the Timer event.
VB Code:
Private Sub Timer1_Timer()
Dim nNumber As Long
nNumber = Text1.Text 'this assumes the display textbox is called Text1
If blnCountDown = True Then
nNumber = nNumber - 1
Else
nNumber = nNumber + 1
End If
'update the display
Text1.Text = nNumber
End Sub
The above code has a potential bug in it since I declared nNumber as a Long it would cause an Error if the content of the textbox is not numeric, but I leave that to you to figure out a solution for .
-
May 3rd, 2005, 07:14 PM
#8
Re: Timer- Newbie
 Originally Posted by coralie
Hey People thanx for the replies but i'am still a bit stuck coz ive beed asked specifically for two command buttons on it..one counting up and one counting down, cant even get it to count up at the mo lol. I'm really new to this and my tutor z its fairly simple but wont give us ne help..just have to figure it out for our selves! hmm.
You've got all the pieces so just try to put them together ...
Good luck.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|