By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,642 Members | 2,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,642 IT Pros & Developers. It's quick & easy.

calculate amount of hours worked

100+
P: 153
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
Nov 30 '07 #1
Share this Question
Share on Google+
9 Replies


debasisdas
Expert 5K+
P: 8,127
Instead of using textbox try to use DtPicker for time entry

set the format to dtptime.

why u have declared all the variant variables ?
Nov 30 '07 #2

lotus18
100+
P: 866
Hi brendanmcdonagh

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

Rey Sean
Nov 30 '07 #3

100+
P: 153
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
Nov 30 '07 #4

100+
P: 153
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!
Nov 30 '07 #5

lotus18
100+
P: 866
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
Nov 30 '07 #6

100+
P: 153
thank you so much - again!!
Nov 30 '07 #7

lotus18
100+
P: 866
thank you so much - again!!
You're much welcome. Good Luck : )

Rey Sean
Nov 30 '07 #8

hariharanmca
100+
P: 1,977
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.
Nov 30 '07 #9

lotus18
100+
P: 866
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
Nov 30 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.