+ Reply to Thread
Results 1 to 3 of 3

TextBox calculation

  1. #1
    Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    Office 2019 Enterprise
    Posts
    473

    TextBox calculation

    Hello,

    I have 3 textboxes (Labour, Materials and Total)

    I am trying to get the totalcharge textbox to show sum of labour + materials after labour change and/or materials change but it this is what happens:

    Labour = £10.00
    Materials = £5.00
    Total = £10.005 (Instead of just £15.00)
    and if i tab back up to the labour box the totalcharge value changes again to £10.00£5.00

    my code is:


    Private Sub Labour_AfterUpdate()
    TotalCharge.Text = Labour.Value + Materials.Value
    Labour.Text = Format(Labour.Value, "£###,,###.00")
    End Sub
    Private Sub materials_AfterUpdate()
    TotalCharge.Text = Labour.Value + Materials.Value
    Materials.Text = Format(Materials.Value, "£###,,###.00")
    End Sub

    I'm not really sure when to use .text or .value either
    any help would be really appreciated!!

    thanks

  2. #2
    Dave Peterson
    Guest

    Re: TextBox calculation

    I don't think it matters.

    I changed the Pound symbol to my USA setting $ and did this:

    Option Explicit
    Private Sub CommandButton1_Click()
    Unload Me
    End Sub
    Private Sub Labour_AfterUpdate()
    TotalCharge.Text _
    = Format(CDbl(Labour.Value) + CDbl(Materials.Value), "$###,###.00")
    Labour.Text = Format(CDbl(Labour.Value), "$###,###.00")
    End Sub
    Private Sub materials_AfterUpdate()
    TotalCharge.Text _
    = Format(CDbl(Labour.Value) + CDbl(Materials.Value), "$###,###.00")
    Materials.Text = Format(CDbl(Materials.Value), "$###,###.00")
    End Sub
    Private Sub UserForm_Initialize()
    Me.Labour.Text = "$10.00"
    Me.Materials.Text = "$5.00"
    Me.TotalCharge.Text = "$15.00"
    End Sub

    The code was seeing the values in the textboxes as text--cdbl() converted the
    text values (including the currency symbol) to a real number.

    You may want to make sure that there are numbers in those textboxes, too.


    johncassell wrote:
    >
    > Hello,
    >
    > I have 3 textboxes (Labour, Materials and Total)
    >
    > I am trying to get the totalcharge textbox to show sum of labour +
    > materials after labour change and/or materials change but it this is
    > what happens:
    >
    > Labour = £10.00
    > Materials = £5.00
    > Total = £10.005 (Instead of just £15.00)
    > and if i tab back up to the labour box the totalcharge value changes
    > again to £10.00£5.00
    >
    > my code is:
    >
    > Private Sub Labour_AfterUpdate()
    > TotalCharge.Text = Labour.Value + Materials.Value
    > Labour.Text = Format(Labour.Value, "£###,,###.00")
    > End Sub
    > Private Sub materials_AfterUpdate()
    > TotalCharge.Text = Labour.Value + Materials.Value
    > Materials.Text = Format(Materials.Value, "£###,,###.00")
    > End Sub
    >
    > I'm not really sure when to use .text or .value either
    > any help would be really appreciated!!
    >
    > thanks
    >
    > --
    > johncassell
    > ------------------------------------------------------------------------
    > johncassell's Profile: http://www.excelforum.com/member.php...o&userid=25016
    > View this thread: http://www.excelforum.com/showthread...hreadid=385423


    --

    Dave Peterson

  3. #3
    Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    Office 2019 Enterprise
    Posts
    473

    TextBox Calculation

    Thanks a lot that worked brilliantly, i can stop banging my head against the wall now! cheers

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1