|
-
Dec 22nd, 2005, 07:00 AM
#1
Thread Starter
Lively Member
[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
-
Dec 22nd, 2005, 08:05 AM
#2
Re: How to Calculate Textbox value
VB Code:
Text6.Text = Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text) + Val(Text4.Text) + Val(Text5.Text)
-
Dec 22nd, 2005, 09:25 AM
#3
Thread Starter
Lively Member
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.
-
Dec 22nd, 2005, 09:34 AM
#4
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?
-
Dec 22nd, 2005, 09:36 AM
#5
Thread Starter
Lively Member
Re: How to Calculate Textbox value
Mr. Hack , plz check it again, i write it in explain..
-
Dec 22nd, 2005, 09:45 AM
#6
Re: How to Calculate Textbox value
This
VB Code:
Private Sub text6_Change()
text6.Text = Val(text1.Text) + Val(text2.Text) + Val(text3.Text) + Val(text4.Text)
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?
-
Dec 22nd, 2005, 09:46 AM
#7
Hyperactive Member
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?
-
Dec 22nd, 2005, 09:52 AM
#8
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
-
Dec 22nd, 2005, 09:52 AM
#9
Thread Starter
Lively Member
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?
-
Dec 22nd, 2005, 09:54 AM
#10
Thread Starter
Lively Member
Re: How to Calculate Textbox value
Mr. Abhijit,
sorry, i don't know how to write function
-
Dec 22nd, 2005, 09:54 AM
#11
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
-
Dec 22nd, 2005, 09:55 AM
#12
Hyperactive Member
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
-
Dec 22nd, 2005, 09:59 AM
#13
Thread Starter
Lively Member
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..
-
Dec 22nd, 2005, 10:04 AM
#14
Re: How to Calculate Textbox value
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|