CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Join Date
    Feb 2010
    Posts
    15

    Calculation Problem

    Need help in calculating Quantity with Rate. I have Labels as:- Quantity, Rate, Amount, Total of Quantity and Total of Amount.
    Text Box as Quantity Rate And Amount in 4 rows
    What code I should write to get output in Amount, Total of Quantity and Total Amount
    Vivek (viv345)

    Edit by admin: no contact info permitted on the forum, thank you

  2. #2
    Join Date
    Oct 2006
    Posts
    327

    Re: Calculation Problem

    Hello ...
    Very precise explanation and precisions !
    how many labels have you got ?
    are they belonging to an indexed array group ?
    What is Rate, exactly ?
    I am afraid no one could answer without a very efficient crystal bowl !
    Be very precise, please ... Il you are not able to do it with simple words, try with an example of your requirements :
    - I have this (describe/show)
    - and the result would be (describe/show).

  3. #3
    Join Date
    Feb 2010
    Posts
    15

    Post Re: Calculation Problem

    I have got:-

    Labels Quantity Rate Amount
    Text [ ] [ ] [ ]

    Text [ ] [ ] [ ]

    Text [ ] [ ] [ ]




    Label
    Total of Quantity [ ] Total of Amount [ ]

  4. #4
    Join Date
    Feb 2010
    Posts
    15

    Re: Calculation Problem

    I have attached the screen shot for consideration
    Attached Images Attached Images

  5. #5
    Join Date
    Apr 2009
    Posts
    394

    Re: Calculation Problem

    Code:
    Text3.Text = CStr(Val(Text1.Text) * Val(Text2.Text))
    '...8 = 7 * 6
    '...11 = 10 * 9
    Text4.Text = CStr(Val(Text1.Text) + Val(Text6.Text) + Val(Text9.Text))
    '...5 = 3 + 8 + 11


    Good Luck

  6. #6
    Join Date
    Feb 2010
    Posts
    15

    Re: Calculation Problem

    Thanks

  7. #7
    Join Date
    Feb 2010
    Posts
    15

    Re: Calculation Problem

    Sir, after giving the code given by you it is not calculating the Amount. Pl. check what wrong I have done.
    Attached Images Attached Images
    • File Type: jpg 2.jpg (26.5 KB, 74 views)

  8. #8
    Join Date
    Apr 2009
    Posts
    394

    Re: Calculation Problem

    Well it seems that you have more than one Text3 control... Do you know how I know this??? (Index As Integer)...

    So, first make sure that you only have one text box control named Text3 and make sure its index property is a blank (has no value on property page). Then remove Index As Integer from your sub...



    Good Luck

  9. #9
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Calculation Problem

    Also, don't calculate Text3 when it changes. You want to calculate only when Text1 or Text2 changes!
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  10. #10
    Join Date
    Apr 2009
    Posts
    394

    Re: Calculation Problem

    Good catch dglienna, I totally missed that ...

  11. #11
    Join Date
    Feb 2010
    Posts
    15

    Re: Calculation Problem

    Sorry Sir not got your point. Can you please in detail.

    [Private Sub Text3_Change(Index As Integer)
    Text3.Text = CStr(Val(Text1.Text) * Val(Text2.Text))
    End Sub]

    Should i remove Private SubText3_****(Index as Integer)
    Plz.

  12. #12
    Join Date
    Feb 2010
    Posts
    15

    Re: Calculation Problem

    i am new in programming.

  13. #13
    Join Date
    Apr 2009
    Posts
    394

    Re: Calculation Problem

    No, please reread post slowly and carefully and follow D's advice...

  14. #14
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Calculation Problem

    Please check the names of yll your textboxes and you will find mor than one textbox with the name of Text3. It seems that you might have created a TextBox array, possibly by incident without wanting that.
    It becomes obvious because the change event of box Text3 gets the Index Parameter.
    A normal TextBox event does not get a parameter supplied.

    What you are supposed to do:
    When you have located the Text3 boxes, give one of them a new name.
    Then in bith of them remove the Index property. Simply delete the number in the property list.
    Index property must be blank.

    Then you reconsider Davids hint, that you dont want to change Text3 while it is already changing. This will create an endless loop.

    The statement: Text3.Text = CStr(Val(Text1.Text) * Val(Text2.Text))
    has to go to the Change() events of Text1 and Text2, not to Text3_Change() at all

  15. #15
    Join Date
    Feb 2010
    Posts
    15

    Re: Calculation Problem

    In this way:
    [Private Sub Text_Change()
    Text3.Text = CStr(Val(Text1.Text) * Val(Text2.Text))
    End Sub]
    OR
    [Private Sub Text1_Change(Text2.Text)
    Text3.Text = CStr(Val(Text1.Text) * Val(Text2.Text))
    End Sub]

Page 1 of 2 12 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured