| | |
Time Difference in VB 6.0
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 6
Reputation:
Solved Threads: 0
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
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
•
•
•
•
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?
A conclusion is the place where you got tired of thinking. http://www.martin2k.co.uk/forums/index.php?showforum=4
http://www.a1vbcode.com/a1vbcode/vbforums/Forum3-1.aspx
http://www.developerfusion.co.uk/for...orum&ForumID=4
•
•
Join Date: Oct 2008
Posts: 6
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- time difference in vb6 (Visual Basic 4 / 5 / 6)
- Time Difference with precision (C)
- Time difference (MS Access and FileMaker Pro)
- Calculating Time Difference (C++)
- Elapsed time for retriving data from database (Visual Basic 4 / 5 / 6)
- Execution time (C)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: How do you calculate prime numbers??
- Next Thread: Tab Key in VB6
Views: 3671 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp c++ calculator cd cells.find click client code college column connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window






