Connecting Tech Pros Worldwide Help | Site Map

calculate amount of hours worked

Familiar Sight
 
Join Date: Nov 2007
Posts: 153
#1: Nov 30 '07
Hi,

I am designing a project for my friend as I am just a week old baby to vb and want to implement what I've learnt so far.

She wants to be able to put start time, end time and lunch for each day and then calculate amount of hours worked. So far I have designed form and added code to calculate textbox inputs, (which works!).

However, I didn't think of this at beginning. Say I put .30 for lunch, when I get total hours worked the answer would be .70 as it's taking .30 away from 1. (Sounds obvious now!) I want it to calculate as minutes in an hour. Is there a way of telling the project half nine is 9.30 instead of having to input 9.50 ?

Any comments would be appreciated
Expand|Select|Wrap|Line Numbers
  1. Dim SunTotal As Variant
  2. Dim MonTotal As Variant
  3. Dim TuesTotal As Variant
  4. Dim WedsTotal As Variant
  5. Dim Thurstotal As Variant
  6. Dim FriTotal As Variant
  7. Dim SatTotal As Variant
  8.  
  9. Dim HoursTotal As Variant
  10.  
  11. Dim valsunend As Variant
  12. Dim valmonend As Variant
  13. Dim valtuesend As Variant
  14. Dim valwedsend As Variant
  15. Dim valthursend As Variant
  16. Dim valfriend As Variant
  17. Dim valsatend As Variant
  18.  
  19. Dim valsunstart As Variant
  20. Dim valmonstart As Variant
  21. Dim valtuesstart As Variant
  22. Dim valwedsstart As Variant
  23. Dim valthursstart As Variant
  24. Dim valfristart As Variant
  25. Dim valsatstart As Variant
  26.  
  27. Dim valsunlunch As Variant
  28. Dim valmonlunch As Variant
  29. Dim valtueslunch As Variant
  30. Dim valwedslunch As Variant
  31. Dim valthurslunch As Variant
  32. Dim valfrilunch As Variant
  33. Dim valsatlunch As Variant
  34.  
  35. Private Sub CmdCalculate_Click()
  36. valsunend = Val(TxtSunEnd.Text)
  37. valmonend = Val(TxtMonEnd.Text)
  38. valtuesend = Val(TxtTuesEnd.Text)
  39. valwedsend = Val(TxtWedsEnd.Text)
  40. valthursend = Val(TxtThursEnd.Text)
  41. valfriend = Val(TxtFriEnd.Text)
  42. valsatend = Val(TxtSatEnd.Text)
  43.  
  44. valsunstart = Val(TxtSunStart.Text)
  45. valmonstart = Val(TxtMonStart.Text)
  46. valtuesstart = Val(TxtTuesStart.Text)
  47. valwedsstart = Val(TxtWedsStart.Text)
  48. valthursstart = Val(TxtThursStart.Text)
  49. valfristart = Val(TxtFriStart.Text)
  50. valsatstart = Val(TxtSatStart.Text)
  51.  
  52. valsunlunch = Val(TxtSunLunch.Text)
  53. valmonlunch = Val(TxtMonLunch.Text)
  54. valtueslunch = Val(TxtTuesLunch.Text)
  55. valwedslunch = Val(TxtWedsLunch.Text)
  56. valthurslunch = Val(TxtThursLunch.Text)
  57. valfrilunch = Val(TxtFriLunch.Text)
  58. valsatlunch = Val(TxtSatLunch.Text)
  59.  
  60. SunTotal = valsunend - valsunstart - valsunlunch
  61. MonTotal = valmonend - valmonstart - valmonlunch
  62. TuesTotal = valtuesend - valtuesstart - valtueslunch
  63. WedsTotal = valwedsend - valwedsstart - valwedslunch
  64. Thurstotal = valthursend - valthursstart - valthurslunch
  65. FriTotal = valfriend - valfristart - valfrilunch
  66. SatTotal = valsatend - valsatstart - valsatlunch
  67.  
  68. HoursTotal = SunTotal + MonTotal + TuesTotal + WedsTotal + Thurstotal + FriTotal + SatTotal
  69. LblHours.Caption = HoursTotal
  70. End Sub
debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,505
#2: Nov 30 '07

re: calculate amount of hours worked


Instead of using textbox try to use DtPicker for time entry

set the format to dtptime.

why u have declared all the variant variables ?
lotus18's Avatar
Site Addict
 
Join Date: Nov 2007
Location: Zamboanga City, Philippines
Posts: 857
#3: Nov 30 '07

re: calculate amount of hours worked


Hi brendanmcdonagh

Or you can create a combobox and list down all the time that you wanted : )

Rey Sean
Familiar Sight
 
Join Date: Nov 2007
Posts: 153
#4: Nov 30 '07

re: calculate amount of hours worked


Set as Variants as new to vb so will look up what they really need to be in a bit - Thanks for that.

Combo not really an option as different time options are a lot.

DtPicker - need to look that up -

So grateful for everyone helping thank you
Familiar Sight
 
Join Date: Nov 2007
Posts: 153
#5: Nov 30 '07

re: calculate amount of hours worked


Can anyone point me in right direction as to how to get to dtpicker, i've searched but no instructions how to actually get to it. I'll do the rest from there I promise!
lotus18's Avatar
Site Addict
 
Join Date: Nov 2007
Location: Zamboanga City, Philippines
Posts: 857
#6: Nov 30 '07

re: calculate amount of hours worked


Quote:

Originally Posted by brendanmcdonagh

Can anyone point me in right direction as to how to get to dtpicker, i've searched but no instructions how to actually get to it. I'll do the rest from there I promise!

From the toolbar, right-click then select Component... From the Control tab, select MS Windows Common-2 6.0

Rey Sean
Familiar Sight
 
Join Date: Nov 2007
Posts: 153
#7: Nov 30 '07

re: calculate amount of hours worked


thank you so much - again!!
lotus18's Avatar
Site Addict
 
Join Date: Nov 2007
Location: Zamboanga City, Philippines
Posts: 857
#8: Nov 30 '07

re: calculate amount of hours worked


Quote:

Originally Posted by brendanmcdonagh

thank you so much - again!!

You're much welcome. Good Luck : )

Rey Sean
hariharanmca's Avatar
Lives Here
 
Join Date: Dec 2006
Location: Banglore/India
Posts: 1,987
#9: Nov 30 '07

re: calculate amount of hours worked


Why you are using variant type (variant data type will convert data type itself when we assign value), It seems total of hours. Better use integer type.

Use a combo box for sun–to–sat day and three DTPDateTimepicker so it will speed up your form load and save more space in form.
lotus18's Avatar
Site Addict
 
Join Date: Nov 2007
Location: Zamboanga City, Philippines
Posts: 857
#10: Nov 30 '07

re: calculate amount of hours worked


Quote:

Originally Posted by hariharanmca

Why you are using variant type (variant data type will convert data type itself when we assign value), It seems total of hours. Better use integer type.

Use a combo box for sun–to–sat day and three DTPDateTimepicker so it will speed up your form load and save more space in form.

Yes I agree, variant consumes more memory space than defining the datatype, I think : )

Rey Sean
Reply