Results 1 to 14 of 14

Thread: [RESOLVED] How to Calculate Textbox value

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Resolved [RESOLVED] How to Calculate Textbox value

    Salutations;
    I have 5 texboxex on my form, i want to calculage the numeric value in side these boxes, and the total must appear in the textbox 6.
    Using Access and VB6

    Simple question, reply soon.
    thanx in advance

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to Calculate Textbox value

    VB Code:
    1. Text6.Text = Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text) + Val(Text4.Text) + Val(Text5.Text)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Re: How to Calculate Textbox value

    My Dear Hack,
    It is not working, i know the code you wrote is OK, but it not working, i am using already this code, take a look, but it is not working plz help.

    Code on ****text1.text****

    Private Sub text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    text2.SetFocus
    End If
    Select Case KeyAscii
    Case 48 To 57, 46, 8
    'do nothing
    Case Else
    KeyAscii = 0
    End Select
    End Sub
    **************** this is code is same on rest of 4 text boxes.
    After entering value in each text box i need the sum ov values in textbox 6, as i Questioned before.

    and in ********** textbox 6 i write this code...


    Private Sub text6_Change()
    text6.Text = Val(text1.Text) + Val(text2.Text) + Val(text3.Text) + Val(text4.Text)
    End Sub

    But it is not working.. plz help,
    Last edited by Plucky; Dec 22nd, 2005 at 09:42 AM.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to Calculate Textbox value

    Why are you putting it in the Keypress event of text1 as opposed to the click event of a command button?

    What does "its not working" mean? What is happening?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Re: How to Calculate Textbox value

    Mr. Hack , plz check it again, i write it in explain..

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to Calculate Textbox value

    This
    VB Code:
    1. Private Sub text6_Change()
    2. text6.Text = Val(text1.Text) + Val(text2.Text) + Val(text3.Text) + Val(text4.Text)
    3. End Sub
    is never ever going to get executed unless you type something into Text6. Actually entering something into a textbox is the ONLY way the Change event ever fires.

    So, again, I ask, why not put that code in a command button's click event, and after everything is entered into all five textboxes, click the button and get the total?

  7. #7
    Hyperactive Member
    Join Date
    May 2005
    Posts
    307

    Re: How to Calculate Textbox value

    Plucky why you putting this:
    text6.Text = Val(text1.Text) + Val(text2.Text) + Val(text3.Text) + Val(text4.Text)

    in the text6_change event?

  8. #8
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: How to Calculate Textbox value

    Why have you posted this question twice?

    So you want to calculate as the user types. In that case you need to write code in the change event for each text box.
    Call a function in the textbox change event.
    In the function write the adding up code that Hack has posted.
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Re: How to Calculate Textbox value

    Sir, Whythetorment
    Becuase i need total of values those i entered in text1.text, text2.text...... text5.text text6.text,

    Is it wrong mathod?

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Re: How to Calculate Textbox value

    Mr. Abhijit,
    sorry, i don't know how to write function

  11. #11
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: How to Calculate Textbox value

    Plucky,
    Its not right. You will have to place the code in the change event of the other text boxes. Thats when its going to work.
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  12. #12
    Hyperactive Member
    Join Date
    May 2005
    Posts
    307

    Re: How to Calculate Textbox value

    yes but like hack said its not going to work like that unless you type in text6. place the code in the text1_change, text2_change, etc.

    public sub text1_change()
    text6.Text = Val(text1.Text) + Val(text2.Text) + Val(text3.Text) + Val(text4.Text)
    end sub

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Re: How to Calculate Textbox value

    Mr. Hack, thank you very much, its working now..
    i just put keypress in text6, now it is working..
    Thanx again you are all great..

  14. #14
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to Calculate Textbox value

    Quote Originally Posted by Plucky
    Mr. Hack, thank you very much, its working now..
    i just put keypress in text6, now it is working..
    Thanx again you are all great..
    You never did say why you aren't putting the calculation in command button's click event instead of each textbox's change event, but I'm guessing that you want Text6 to reflect a running total of the other 5 box's input. Is that right?

    By the way, if this is resolved, please pull down the Thread Tools menu and click the Mark Thread Resolved button. That will let everyone know that you have your answer.

    Thank you.

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