calculate amount of hours worked

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brendanmcdonagh
    New Member
    • Nov 2007
    • 153

    calculate amount of hours worked

    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
    [code=vb]
    Dim SunTotal As Variant
    Dim MonTotal As Variant
    Dim TuesTotal As Variant
    Dim WedsTotal As Variant
    Dim Thurstotal As Variant
    Dim FriTotal As Variant
    Dim SatTotal As Variant

    Dim HoursTotal As Variant

    Dim valsunend As Variant
    Dim valmonend As Variant
    Dim valtuesend As Variant
    Dim valwedsend As Variant
    Dim valthursend As Variant
    Dim valfriend As Variant
    Dim valsatend As Variant

    Dim valsunstart As Variant
    Dim valmonstart As Variant
    Dim valtuesstart As Variant
    Dim valwedsstart As Variant
    Dim valthursstart As Variant
    Dim valfristart As Variant
    Dim valsatstart As Variant

    Dim valsunlunch As Variant
    Dim valmonlunch As Variant
    Dim valtueslunch As Variant
    Dim valwedslunch As Variant
    Dim valthurslunch As Variant
    Dim valfrilunch As Variant
    Dim valsatlunch As Variant

    Private Sub CmdCalculate_Cl ick()
    valsunend = Val(TxtSunEnd.T ext)
    valmonend = Val(TxtMonEnd.T ext)
    valtuesend = Val(TxtTuesEnd. Text)
    valwedsend = Val(TxtWedsEnd. Text)
    valthursend = Val(TxtThursEnd .Text)
    valfriend = Val(TxtFriEnd.T ext)
    valsatend = Val(TxtSatEnd.T ext)

    valsunstart = Val(TxtSunStart .Text)
    valmonstart = Val(TxtMonStart .Text)
    valtuesstart = Val(TxtTuesStar t.Text)
    valwedsstart = Val(TxtWedsStar t.Text)
    valthursstart = Val(TxtThursSta rt.Text)
    valfristart = Val(TxtFriStart .Text)
    valsatstart = Val(TxtSatStart .Text)

    valsunlunch = Val(TxtSunLunch .Text)
    valmonlunch = Val(TxtMonLunch .Text)
    valtueslunch = Val(TxtTuesLunc h.Text)
    valwedslunch = Val(TxtWedsLunc h.Text)
    valthurslunch = Val(TxtThursLun ch.Text)
    valfrilunch = Val(TxtFriLunch .Text)
    valsatlunch = Val(TxtSatLunch .Text)

    SunTotal = valsunend - valsunstart - valsunlunch
    MonTotal = valmonend - valmonstart - valmonlunch
    TuesTotal = valtuesend - valtuesstart - valtueslunch
    WedsTotal = valwedsend - valwedsstart - valwedslunch
    Thurstotal = valthursend - valthursstart - valthurslunch
    FriTotal = valfriend - valfristart - valfrilunch
    SatTotal = valsatend - valsatstart - valsatlunch

    HoursTotal = SunTotal + MonTotal + TuesTotal + WedsTotal + Thurstotal + FriTotal + SatTotal
    LblHours.Captio n = HoursTotal
    End Sub[/code]
    Last edited by debasisdas; Nov 30 '07, 01:03 PM. Reason: Formatted using code=vb tags
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Instead of using textbox try to use DtPicker for time entry

    set the format to dtptime.

    why u have declared all the variant variables ?

    Comment

    • lotus18
      Contributor
      • Nov 2007
      • 865

      #3
      Hi brendanmcdonagh

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

      Rey Sean

      Comment

      • brendanmcdonagh
        New Member
        • Nov 2007
        • 153

        #4
        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

        Comment

        • brendanmcdonagh
          New Member
          • Nov 2007
          • 153

          #5
          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!

          Comment

          • lotus18
            Contributor
            • Nov 2007
            • 865

            #6
            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

            Comment

            • brendanmcdonagh
              New Member
              • Nov 2007
              • 153

              #7
              thank you so much - again!!

              Comment

              • lotus18
                Contributor
                • Nov 2007
                • 865

                #8
                Originally posted by brendanmcdonagh
                thank you so much - again!!
                You're much welcome. Good Luck : )

                Rey Sean

                Comment

                • hariharanmca
                  Top Contributor
                  • Dec 2006
                  • 1977

                  #9
                  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 DTPDateTimepick er so it will speed up your form load and save more space in form.

                  Comment

                  • lotus18
                    Contributor
                    • Nov 2007
                    • 865

                    #10
                    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 DTPDateTimepick er 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

                    Comment

                    Working...