Community discussion forum

Help on counter...Thanks in advance!!

Tags: vb6 India
  • 1 year ago

    I need to make a counter  with just label and timer, any idea how to start it.

    Was thinking of using For Next but don know how to start it.

  • 1 year ago
    hi use for loop as following dim intCtr as integer for intCtr =0 to 10 debug.print intCtr next regards manpreet singh dhillon hoshiarpur
  • 1 year ago

     

    Sorry guys i'm like totally new to this and cant understand what you  guys have said. Lets say if must use 1 label to display second, 1 label for minute, 1 label for hour, 1 button for start and 1 button to stop the counting. Som how should i go about using a for next loop? 

    Thanks guys.

  • 1 year ago

    Sorry joeyboi, this forum is intended to help software designers or programmers and not to solve the homework of any one.

    Mohan Krishna already gave you a good solution (simple, very clear and very close to your requirements). If you dont understand his solution, just press F1 on every command and read the online help carefully. I also suggest you to read the very basics of VB or any other programing language first. Loops (like the For...Next you mentioned in your first post) are mission critical for writing programs and you must have understood these basics BEFORE you start programing.

  • 1 year ago

     

    Ummm yea got to agree with him, why in the world would you use a for next loop??? Mohan Krishna's solution is quite simple and clean indeed but not quite what I think this guy wants. What you need is public varables that hold minutes seconds and hours. You have a timer set to 1000ms that increases the second varable, when the second varable hits 60 it resets to 0 and increases the minute by 1, when the minute hits 60 it resets to 0 and increases the hour one, very simple, if you need code let me know.
  • 1 year ago

    Yes please, code is what i need.

  • 1 year ago

    Yep. But the point of homework (we have seen this one appear in this forum before) is that you are to write the code.

    To do what you need to do:

    One button (Start) will need to  start a timer control, which triggers every second, or more frequently.

    It also records the current time into a variable.

    One button (Stop) will stops the timer control.

     

    Every time the timer event fires, compare the time now with the time at which the START button was pressed, held in the variable.

    get the difference in seconds.

    Take seconds MOD 60  and put that into the seconds label

    Divide by 60 to get minutes.

    Take minutes MOD 60 and put that into the minutes label

    Divide by 60 to get hours

    Take hours mod 24 and put that into the Hours label.

    .. and so on

     

     

     

  • 1 year ago

     Ok Kid this is about as easy as it gets, you need 3 labels and 2 command buttons:<p><br>

    Public daMinutes As Integer
    Public daHours As Integer
    Public daSeconds As Integer


    Private Sub Command1_Click()
    Timer1.Enabled = True

    End Sub

    Private Sub Command2_Click()
    Timer1.Enabled = False
    daSeconds = 0
    daMinutes = 0
    daHours = 0
    End Sub

    Private Sub Form_Load()

    End Sub

    Private Sub Timer1_Timer()
    daSeconds = daSeconds + 1
        If daSeconds = 60 Then
                                daMinutes = daMinutes + 1
                                daSeconds = 0
                                End If
                                
       If daMinutes = 60 Then
                                daHours = daHours + 1
                                daMinutes = 0
                                End If
    Label3.Caption = daSeconds
    Label2.Caption = daMinutes
    Label1.Caption = daHours

    End Sub

     

    <p><br>

    These guys seem to think your trying to cheat on your homework, hope that isn't true, because not only will you not learn this very basic stuff, but it is also super lame.

     

  • 1 year ago

    Hey man that helps alot, thanks.

    Yeah its my homework, but i was told to source for answer ourselves cause its like 'HE'

    did not teach us anything about timer yet.

    And by the way don you think i can understand alot better when i get the answer and i SO understand it.

    Cheers.

  • 1 year ago

     You really should try and solve yourself first though. This is very basic. Besides 1/2 the fun of coding is trying to come up with a solution, (the other 1/2 of the fun is trying to improve your solution.)

     

Post a reply

Enter your message below

Sign in or Join us (it's free).

Want to stay in touch with what's going on? Follow us on twitter!