473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

calculate amount of hours worked

153 100+
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
9 2455
debasisdas
8,127 Expert 4TB
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
866 512MB
Hi brendanmcdonagh

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

Rey Sean
Nov 30 '07 #3
brendanmcdonagh
153 100+
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
brendanmcdonagh
153 100+
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
866 512MB
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
brendanmcdonagh
153 100+
thank you so much - again!!
Nov 30 '07 #7
lotus18
866 512MB
thank you so much - again!!
You're much welcome. Good Luck : )

Rey Sean
Nov 30 '07 #8
hariharanmca
1,977 1GB
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
866 512MB
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

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

Similar topics

1
by: sg_s123 | last post by:
============================================================================ 02-Feb-04 03-Feb-04 Staff Staff 0800hr- 1300hr- 1700hr- 1900hr- 0800hr- 1300hr- 1700hr- 1900hr- Number...
5
by: cvisal | last post by:
Hi all Im working on productivity calculations (Time calculations) and need some help in coding. Database Tool:MS-Access 2003. The general operator punch-in time is 5:30 AM and the punch-out...
6
by: Programador | last post by:
I'm getting this error when running this program: Cannot calculate rate using the arguments provided Module Module1 Sub Main() Rate(360, -694.44444444444446, 244274.69178082192) End Sub
3
by: Michelle Anderson | last post by:
I have an access form. In the form, it co ntains 3 fields : Type, hours, and Amount. Field "Type" is a combo box and it contains 2 values: Standard and Rush Field " Hours" is just a numeric...
1
by: deena22 | last post by:
hello, i'm using 'Access database' and VB 6.0. My database is named ' timesheet' and it contains a table named 'tabletimesheet'. The table contain the following fields: 'staffname, stafftype,...
4
by: Sector 7G | last post by:
I'm working with a SQL query for a Human Resources database. Its intended purpose is to find all the paycheck records with a check date (prckhist.chkdate ) more recent than eleven days past the...
28
by: DavidOwens | last post by:
hey guys i want to have a html form which users would fil in and they click display and it would be update to another form and calculations carried out e.g so just say they filled forms were it...
5
by: brendanmcdonagh | last post by:
Hi, I have been learning VB now for about a week and thought I was doing ok. I have already done a calculation form (not as big as this) . I have volunteered myself to help a friend input her hours...
15
by: student4lifer | last post by:
Hello, I have 2 time fields dynamically generated in format "m/d/y H:m". Could someone show me a good function to calculate the time interval difference in minutes? I played with strtotime() but...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.