Results 1 to 8 of 8

Thread: Timer- Newbie

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    5

    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

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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:
    1. 'you may use menu item to set each interval or perhaps buttons or textbox ...
    2. Timer1.Interval = 100   '1/10 th of second
    3. Timer1.Interval = 1000  '1 second
    4. Timer1.Interval = 10000 '10 seconds
    5.  
    6. 'to reset timer use this:
    7. Private Sub Command1_Click()
    8.     Timer1.Enabled = Not Timer1.Enabled
    9. End Sub

  3. #3
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    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:
    1. Private Sub Label1_mousedown()
    2. If button = vbRightButton Then
    3. PopupMenu MENU NAME, vbPopupMenuRightButton
    4. End If
    5. End Sub

    Hope this helped...

    -Sir Loin

  4. #4
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Timer- Newbie

    I helped someone making a countdown earlier:

    http://www.vbforums.com/showthread.p...highlight=time

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    5

    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.

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Timer- Newbie

    Post your code.

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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:
    1. Private Sub Timer1_Timer()
    2.     Dim nNumber As Long
    3.  
    4.     nNumber = Text1.Text 'this assumes the display textbox is called Text1
    5.     If blnCountDown = True Then
    6.         nNumber = nNumber - 1
    7.     Else
    8.         nNumber = nNumber + 1
    9.     End If
    10.     'update the display
    11.     Text1.Text = nNumber
    12. 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 .

  8. #8
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Timer- Newbie

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



Click Here to Expand Forum to Full Width