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