Keeping track of time

im trying to make a program that will keep track of time not real time

i have a label that holds the time i set in 00:00 format

i have 3 buttons and a label on the form
 
buttton 1 would Increment the time one minute
button 2 would Increment the time 10 minutes
and buttom 3 would would Increment the time to the next 15 minutes

for example
start time 04:00
click bitton 1: 4:01
click bitton 1: 4:02
click bitton 1: 4:03
click bitton 1: 4:04
click bitton 2: 4:14
click bitton 2: 4:24
click bitton 3: 4:30 (this is the rounding i need)
click bitton 3: 4:45
click bitton 3: 5:00

Can this be done
All help is greatly appreciated
thank you

 
 
 
 
 
 
440Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VbmasterCommented:
You can add a time interval to a date variable using the DateAdd function, it's really easy you just have to check the help file on the DateAdd Function.
0
sky71276Commented:
It's quite easy if you keep the time in a separate variable (int or long int) as a number of minutes (no format). The formatting happens only in the textbox. The buttons then will add the wanted number of minutes to the variable.
The tricky part is the one with the rounding, but in fact, it's quite easy with the following code :

Private Sub Command3_Click()

    Minutes = Minutes + 15
    Minutes = Minutes - (Minutes Mod 15)
   
End Sub

This code will add 15 minutes to the total of minutes (line 1) and then it will substract the remainder of the division by 15.
The formatting in the textbox can be like this :

Private Sub FormatTime()

    Dim intHour As Integer
    Dim intminute As Integer
   
    intHour = Minutes \ 60
    intminute = Minutes Mod 60
    Text1 = Format(intHour & ":" & intminute, "H:MM")
   
   
End Sub
0
440Author Commented:
I Cant Get it to do anything can you give me more details i am new and dont understand how to get it to work
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

sky71276Commented:
What I've made is a project with 1 form (Form1), 1 textbox (Text1) and 3 Command Buttons (Command1, Command2 and Command3).
I use 1 public variable (Minutes) to store the total of minutes. (if this is 205, the time will be 3:25)

The starting time is determined in the procedure that is run when the form loads (in this example it is 0 minutes, so it's 0:00)

Command1 will add 1 minute to the time, Command2 10 minutes and Command3 will increment time to the next full quarter.
So, the procedure Command1.Click will add 1 minute to the total of minutes, Command2.Click 10 minutes, but the Command3.Click procedure will add 15 minutes and will then round to the lower whole quarter.
This can be done by calculating the remainder of the division of the total of minutes by 15 and subtracting this remainder from the total of minutes.

When any of these 3 buttons is pressed, the procedure FormatTime is called. This procedure will calculate the number of hours and minutes and will display the time in the correct format in Text1.

This is all the code I used :

Public Minutes As Long

Private Sub Command1_Click()

    Minutes = Minutes + 1
    FormatTime
   
End Sub

Private Sub Command2_Click()

    Minutes = Minutes + 10
    FormatTime
   
End Sub

Private Sub Command3_Click()

    Minutes = Minutes + 15
    Minutes = Minutes - (Minutes Mod 15)
    FormatTime
   
End Sub

Private Sub FormatTime()

    Dim intHour As Integer
    Dim intMinute As Integer
   
    intHour = Minutes \ 60
    intMinute = Minutes Mod 60
    Text1 = Format(intHour & ":" & intMinute, "HH:MM")
   
   
End Sub

Private Sub Form_Load()

    Minutes = 0
    FormatTime
   
End Sub
0
mcriderCommented:
Here you go... If this helps you, please reject the current answer and select this comment as the answer.

Add the following to a MODULE in your program:

    Public Enum DAinterval
        OneMinute = 1
        TenMinutes = 2
        FifteenMinutes = 3
    End Enum
    Function AddTime(sTime As String, Interval As DAinterval) As String
        Dim x As Date
        Dim iVal As Integer
        x = CDate(sTime + ":00")
        Select Case Interval
            Case DAinterval.OneMinute
                x = DateAdd("n", 1, x)
            Case DAinterval.TenMinutes
                x = DateAdd("n", 10, x)
            Case DAinterval.FifteenMinutes
                Do
                    x = DateAdd("n", 1, x)
                    Select Case Format(x, "nn")
                        Case "00", "15", "30", "45"
                            Exit Do
                    End Select
                Loop
        End Select
        AddTime = Format(x, "hh:nn")
    End Function



Then assuming that label1 gets initialized with "00:00", you can do something like this in button 1:

     Label1.Caption = AddTime(Label1.Caption,OneMinute)

Button 2 would look like this:

     Label1.Caption = AddTime(Label1.Caption,TenMinutes)

And button 3 would look like this:

     Label1.Caption= AddTime(Label1.Caption,FifteenMinutes)



Hope this helps!


Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
440Author Commented:
i used mcrider comment thankyou for the help
0
mcriderCommented:
Thanks for the points! Glad I could help!


Cheers!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.