Time Difference in VB 6.0

Reply

Join Date: Oct 2008
Posts: 6
Reputation: DhruvaRai is an unknown quantity at this point 
Solved Threads: 0
DhruvaRai DhruvaRai is offline Offline
Newbie Poster

Time Difference in VB 6.0

 
0
  #1
Oct 18th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,086
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 124
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: Time Difference in VB 6.0

 
0
  #2
Oct 19th, 2008
you need to format the time value properly before processing.

everything is possible ,but nothing happens automatically. You need to code that.
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 44
Reputation: K.Vanlalliana is an unknown quantity at this point 
Solved Threads: 3
K.Vanlalliana K.Vanlalliana is offline Offline
Light Poster

Re: Time Difference in VB 6.0

 
0
  #3
Oct 19th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 300
Reputation: jireh is an unknown quantity at this point 
Solved Threads: 42
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz

Re: Time Difference in VB 6.0

 
0
  #4
Oct 20th, 2008
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...
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 6
Reputation: DhruvaRai is an unknown quantity at this point 
Solved Threads: 0
DhruvaRai DhruvaRai is offline Offline
Newbie Poster

Re: Time Difference in VB 6.0

 
0
  #5
Oct 21st, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,086
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 124
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: Time Difference in VB 6.0

 
0
  #6
Oct 21st, 2008
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.
Share your Knowledge.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC