Trying to calculate Text Box inputs - please help!

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

    Trying to calculate Text Box inputs - please help!

    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 per day into a form, start time, end time and lunch time. Then the form will calculate the amount of hours she has done for her. Sending results to access is not an issue yet!

    When I have entered the below code and tested it, it let's me input hours, I press calculate then says compile error, method or data member not found. I press ok and .text is highlighted. I have noticed when I delete .text and type it again only 4 options instead of loads comes up. So really it's not letting me selct it as .text.

    I was up til 4 this morning with this so any help and I would be eternally grateful.

    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
    Last edited by brendanmcdonagh; Nov 30 '07, 10:41 AM. Reason: text
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    Do you get Error on all the lines of "txt.Text". ..?
    Instead of Variant, Try to Decalare all the Variables as Single/Double Or Currency..

    Regards
    Veena

    Comment

    • brendanmcdonagh
      New Member
      • Nov 2007
      • 153

      #3
      Originally posted by QVeen72
      Hi,

      Do you get Error on all the lines of "txt.Text". ..?
      Instead of Variant, Try to Decalare all the Variables as Single/Double Or Currency..

      Regards
      Veena
      Hi I'll try it now,

      Thanks for swift response - letyou know!

      Comment

      • brendanmcdonagh
        New Member
        • Nov 2007
        • 153

        #4
        Hi, Changed all to double, same response. When you say on all lines I don't know because it only shows first line of problem:
        Private Sub CmdCalculate_Cl ick() (being in yellow)
        valsunend = Val(TxtSunEnd.T ext) (.text being highlighted blue.

        The strange thing is that when I go to type something like text1.text on another project it'll offer me the option of filling .text in for me. This project isn't doing that. The auto fill has only 4 options - count, item, lbound and ubound.

        Can't get my head around it.

        Comment

        • QVeen72
          Recognized Expert Top Contributor
          • Oct 2006
          • 1445

          #5
          Originally posted by brendanmcdonagh
          The strange thing is that when I go to type something like text1.text on another project it'll offer me the option of filling .text in for me. This project isn't doing that. The auto fill has only 4 options - count, item, lbound and ubound.
          Can't get my head around it.
          Hi,

          OK, By mistake, you have created a Control Array of TextBoxes.
          In Design Mode, Go to the properties of each TextBox, and Clear Value from this property: "Index" (it will be some Integer value 0,1,..)

          Just Take Care that No TextBox Name is Repeated..

          Regards
          Veena

          Comment

          • brendanmcdonagh
            New Member
            • Nov 2007
            • 153

            #6
            Thank you so much it worked!

            Comment

            Working...