Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combo boxes to record time

Status
Not open for further replies.

keun

Technical User
Jul 15, 2005
262
US
Hey there. I need to have a combobox that users can pick form to record their time spent on a project. I need it to record fractions of hours for the related time. I know that this is easy, I will just make a table with the minutes and the fraction equivalent and users can pick the minutes but the fraction gets stored.
My problem is: what happens when they go over an hour? I want to have two boxes. One stores hours, the other minutes. The hour combo will be whole numbers the minutes will store the fraction. I can do all this. Now I have two combo boxes, side by side. One with hours (or a zero) and one with fraction of an hour.
How do I add these together into a single field? So picking "1" from the hours and ".25" from the minutes is stored and displayed as "1.25"?
 
If the combo boxes are comboH and comboM for Hours and Minutes, and they contain values in decimal like you have them,

Code:
dblTime = comboH.value/24 + comboM.value/60/24

If you made the combo boxes contain "1:00" for hours and "00:15" for minutes, then you could use:

Code:
dblTime = TimeValue(comboH.value) + TimeValue(comboM.value)

Either way will give you a value of 5.20833333333333E-02 which is 1.25 hours for VB.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top