Hi there

I am trying to design a flexi sheet calculator for work so that the users can use this program to calculate their working hours. They enter their times manually over the week. This is a calculator for them to use at the end of each week to calculate the totals.

Eveyday when you arrive at work you log you enter your time in and log out when you go for lunch. Same thing happens when you come back from lunch - log in your time in and time out when you go home.

All times are in 24 hour clock.

Time In1 (hh:mm)
Time Out1 (hh:mm)

Lunch interval

Time in2 (hh:mm)
Time Out2 (hh:mm)

Total hours worked(hh:mm) = (TimeOut1 - TimeIn1) + (TimeOut2 - TimeIn2)

I am not sure how to add or deduct between two sets of times and show the result in hh:mm.

The calculator needs to calculate the number of hours and minutes worked everyday. No seconds required.

Then calculate the total hours worked over 5 days and deduct it from 35 hours which is normal weekly working hours. Any debit or credit hours carried forward to the following week.

I would like the user to be able to simply type 0900 and VB code to convert it to 09:00. Is this possible?

When they type 0900, I would like the cursor to move to the next field automatically rather than having to press the Tab button on the keyboard. Is this possible?

I am new to Visual Basic and trying to learn. If I can do this flexi calculator, it would teach me a lot.

Any help would be grately appreciated. Please do remember I am an idiot when it comes to VB 6.0 but I am very enthusiastic to take your advice and help.

Kind regards
Dhruva Rai

you need to format the time value properly before processing.

everything is possible ,but nothing happens automatically. You need to code that.

Hi, You cannot simply Add or Subtract time, first you need to get the time value and then subtract,

you can get differnces betwen two time or date too as below

TimetoAdd = TimeValue(Text1.Text) + TimeValue(Text2.Text)
Text3.Text = Format(TimetoAdd, "hh:mm:ss AM/PM")


I Hope you will understand now.

I would like the user to be able to simply type 0900 and VB code to convert it to 09:00. Is this possible?

When they type 0900, I would like the cursor to move to the next field automatically rather than having to press the Tab button on the keyboard. Is this possible?

you can use the change event type of the textbox. count the string entered by the user then after the condition was met, format the value as you wished to...

Many Thanks for your advice so far. I am copying my code below but I have not managed to do all I wanted to do.

I have 6 Text boxes in my form. There will be many more when I know how to do Monday first.

MonTimeIn1 to input time in first thing in the morning.
MonTimeOut1 for input time out for lunch.
MonTimeIn2 for to input time in after lunch.
MonTimeOut2 for to input time out before going home.
MonTotalMinsWorked to calculate total minutes worked on Monday.
MonHourMin to convert minutes to hh:mm


Codes:

Option Explicit
'Declaring Variables
Dim DMonTimeIn1 As Date
Dim DMonTimeOut1 As Date
Dim DMonTimeIn2 As Date
Dim DMonTimeOut2 As Date
Dim DMonTotalMinsWorked As Date
Dim DMonHourMin As Date


Private Sub Command1_Click()
'Defining Variables for Monday
DMonTimeIn1 = MonTimeIn1.Text
DMonTimeOut1 = MonTimeOut1.Text
DMonTimeIn2 = MonTimeIn2.Text
DMonTimeOut2 = MonTimeOut2.Text

'Formatting all entries and result text boxes to hh:mm
MonTimeIn1.Text = Format(DMonTimeIn1, "hh:mm")
MonTimeOut1.Text = Format(DMonTimeOut1, "hh:mm")
MonTimeIn2.Text = Format(DMonTimeIn2, "hh:mm")
MonTimeOut2.Text = Format(DMonTimeOut2, "hh:mm")
MonTotalMinsWorked.Text = Format(DMonTotalMinsWorked, "hh:mm")

'Calculating Total Minutes Worked on Monday
MonTotalMinsWorked.Text = (DateDiff("n", DMonTimeIn1, DMonTimeOut1) + DateDiff("n", DMonTimeIn2, DMonTimeOut2))
'Is there a way to show the output of the above line in "hh:mm" rather than in minutes?

'Calculating Total Hours and Minutes in hh:mm format for Monday
MonHourMin.Text = MonTotalMinsWorked.Text / 60 ' This obviously give hours in decimals.

End Sub


My problems:

1. How to format time entry by user from 0900 to 09:00 automatically? _
I would like to avoid typing colon (:) between hour and minute by the users. _
I have formatted the entry field to hh:mm but it does not seem to have _
any affect. Typing colin (:) in the middle of time is really a pain.

2. How to move the cursor to next time entry box without pressing Tab key? _
I have made the length of the field to 5 characters. I would be grateful _
for any help on any LostFocus code. I cannot find LostFocus on VB6, like _
in Microsoft Access.

3. How to convert decimal hours to minutes, i.e. hh:mm.

I would be grateful for some codes on the above. I am hitting the wall now as far as VB 6 is concerned.

I would also welcome any advice on my coding above.

Kind Regards
D R Rai

1.what about simply formatting that using some string function. why not simply take the system time instead of entering the time. that way no one can enter wrong time.
2.you need to code in change event not lostfocus.
3.i dont understand your question.

thanks with your page..i learned things on it..

hi!! could anyone help me to subtract time.. i am not able to subtract the time with the code which you have given.. and i need to take the hours value alone and calculate amount.. so could anyone help me out.. please..

@rasna this thread is almost 2 years old and there is no point to reopen it. Please create new thread, provide relevant coding and explain properly what sort of issues you are facing.

Thread closed!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.