[RESOLVED] how to calculate Textboxes and sum in another textbox
hey
i Have 3 textboxes that i insert numbers inside.
i have another textbox which needs to calculate both of the textboxes
the first one i managed to calculate but all together i cant figure out.
need some help on this.
e.x
if i insert into TxtTenCent number 5 then the TxtSumTotal needs to be 0.50
if i insert into TxtFiftyCent number 2 then the TxtSumTotal needs to be 1.50
this is my code
TxtTenCent.Text = "0.10"
TxtFiftyCent.Text = "0.50"
TxtOneDollar.Text = "1"
TxtSumTotal.text = need to sum the Textboxes
Code:
Private Sub TxtTenCent_Change()
Dim TxtTenCent As String
TxtTenCent = "0.10"
TxtTenCent= Format$(TxtTenCent * val(TxtTenCent.Text), "0.00")
TxtSumTotal.Text = TxtTenCent
End Sub
tnx For Any help
salsa :)
Re: how to calculate Textboxes and sum in another textbox
Hi,
try it like this..
Code:
Private Sub Command3_Click()
Dim curAuto As Currency
Dim curHaus As Currency
Dim curHaushalt As Currency
Dim curHobby As Currency
Dim curGesamtausgaben As Currency
' Eingabefelder in Rechenfelder überführen
curAuto = CCur(Text1.Text) ' 1. Textfeld
curHaus = CCur(Text2.Text) ' 2. Textfeld
curHaushalt = CCur(Text3.Text) ' 3. Textfeld
curHobby = CCur(Text4.Text) ' 4. Textfeld
' Berechnung durchführen
curGesamtausgaben = curAuto + curHaus + curHaushalt + curHobby
' Ausgeben
Label1.Caption = Format$(curGesamtausgaben, "###,##0.00")
End Sub
regards
Chris
Re: how to calculate Textboxes and sum in another textbox
hey chrisE
there is no command button
i am typing inside the textboxes
for E.X
if i have a textbox that value is 0.50 Cent
then if i type the number 5 inside
then the TxtSumTotal.Text = 2.50
if i have a textbox with value 0.10
then if i type 8 inside then its 0.80
TxtSumTotal.Text = 3.30
Re: how to calculate Textboxes and sum in another textbox
Quote:
Originally Posted by
salsa31
hey chrisE
there is no command button
i am typing inside the textboxes
for E.X
if i have a textbox that value is 0.50 Cent
then if i type the number 5 inside
then the TxtSumTotal.Text = 2.50
if i have a textbox with value 0.10
then if i type 8 inside then its 0.80
TxtSumTotal.Text = 3.30
sorry you don't make any sence,
you can also put the routine in the....... Private Sub Text4_LostFocus()
regards
Chris
Re: how to calculate Textboxes and sum in another textbox
Quote:
sorry you don't make any sence
why not?
Code:
Private Sub TxtTenCent_Change()
Dim TxtTenCent As String
TxtTenCent = "0.10"
TxtTenCent= Format$(TxtTenCent * val(TxtTenCent.Text), "0.00")
TxtSumTotal.Text = TxtTenCent
End Sub
this is in the change event of the text box
Re: how to calculate Textboxes and sum in another textbox
have you tried your code ?
I think you want this....
Code:
Public Function AddUp()
Dim curAuto As Currency
Dim curHaus As Currency
Dim curHaushalt As Currency
Dim curHobby As Currency
Dim curGesamtausgaben As Currency
' Eingabefelder in Rechenfelder überführen
curAuto = CCur(Text1.Text) ' 1. Textfeld
curHaus = CCur(Text2.Text) ' 2. Textfeld
curHaushalt = CCur(Text3.Text) ' 3. Textfeld
curHobby = CCur(Text4.Text) ' 4. Textfeld
' Berechnung durchführen
curGesamtausgaben = curAuto + curHaus + curHaushalt + curHobby
Label1.Caption = Format$(curGesamtausgaben, "###,##0.00")
End Function
Private Sub Text1_GotFocus()
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
Private Sub Text1_Change()
AddUp
End Sub
Private Sub Text2_GotFocus()
Text2.SelStart = 0
Text2.SelLength = Len(Text2.Text)
End Sub
Private Sub Text2_Change()
AddUp
End Sub
Private Sub Text3_GotFocus()
Text3.SelStart = 0
Text3.SelLength = Len(Text3.Text)
End Sub
Private Sub Text3_Change()
AddUp
End Sub
Private Sub Text4_GotFocus()
Text4.SelStart = 0
Text4.SelLength = Len(Text4.Text)
End Sub
Private Sub Text4_Change()
AddUp
End Sub
regards
Chris
Re: how to calculate Textboxes and sum in another textbox
Give something like this a try.
Code:
Private Sub txtDollar_Change()
SumAll
End Sub
Private Sub txtFiftyCents_Change()
SumAll
End Sub
Private Sub txtTenCents_Change()
SumAll
End Sub
Private Sub SumAll()
Dim currTenCents As Currency
Dim currFiftyCents As Currency
Dim currDollars As Currency
Dim currTotal As Currency
currTenCents = Val(txtTenCents.Text) * 0.1
currFiftyCents = Val(txtFiftyCents.Text) * 0.5
currDollars = Val(txtDollar.Text)
currTotal = currTenCents + currFiftyCents + currDollars
txtTotal.Text = Format(currTotal, "$0.00")
End Sub
Re: how to calculate Textboxes and sum in another textbox
thank youuuuuuuuuuuuuuuuuuuuuuuuu MARKT :D
long time no see
Re: [RESOLVED] how to calculate Textboxes and sum in another textbox
Ah !
no I understand what you were after salsa
nice one MarkT
regards
Chris
Re: [RESOLVED] how to calculate Textboxes and sum in another textbox
Quote:
Originally Posted by
ChrisE
Ah !
no I understand what you were after salsa
nice one MarkT
regards
Chris
:D yes
Re: [RESOLVED] how to calculate Textboxes and sum in another textbox
hey salsa!
Are you checking to see if only valid numbers are entered into your textboxes?
For example, if you type 6t in one, it won't be correct.
Also, do you have limits? Is 0 an allowable number?
Re: [RESOLVED] how to calculate Textboxes and sum in another textbox
Quote:
Originally Posted by
SamOscarBrown
...
For example, if you type 6t in one, it won't be correct.
...
Since he is using Val, then 6t will be a value of 6 and 6 is a valid number and who is to say it didn't happen to be correct.
Of course t6 would be 0, which may also be OK because if someone is dumb enough to put in garbage, they deserve to get nothing.:rolleyes:
Re: [RESOLVED] how to calculate Textboxes and sum in another textbox
Quote:
Of course t6 would be 0, which may also be OK because if someone is dumb enough to put in garbage, they deserve to get nothing
Must be ya haven't written code for projects for others. Having done so in the past for many years, the wide-range of users out there WILL but t6 in a textbox (intentionally or not) and then call the Help Desk because 'It don't work'! I get your point, but a good programmer will check for all possible textbox entries, and code to ensure only allowable characters are entered (or at least checked before other actions occur based upon what is in that textbox and alert that 'not-so-smart' user out there).
Re: [RESOLVED] how to calculate Textboxes and sum in another textbox
Well, I was trying to be a little humorous and then there is the matter of knowing your customer.
Some posters on forums I find puzzling (there needs to be a more descriptive word, but I can think of a good one).
In particular, I've seen several that are amazingly persistent in pursuing the practice of programming, working and posting questions steadily for years and tackling and asking questions about a wide spectrum of programming tasks.
Yet the mastery of basic programming tasks that is exhibited by the code they post expresses such a dichotomy between desire and ability that I find the existence of such persons both unfathomable and admirable.
For example this bit of code
Code:
Dim TxtTenCent As String
TxtTenCent = "0.10"
TxtTenCent= Format$(TxtTenCent * val(TxtTenCent.Text), "0.00")
Having a string and a textbox with the same name and using the string in a mathematical equation directly would not give me the impression that the coder has been an active programming forum participant and working with VB6 for over six years.
Seeing code of that caliber in a query makes me think that validating the user input is not the highest priority at this stage of their programming "career". I'm not saying it isn't important, but I think having code that works correctly, e.g. uses numeric types for math and avoiding naming conflicts, is usually the first priority.
It also makes me curious about the person who can demonstrate such determination to continue programming given the evidence of the apparent challenges they face with the task. There is something to be admired there.
Re: [RESOLVED] how to calculate Textboxes and sum in another textbox
nice of you to say passel tnk you
Re: [RESOLVED] how to calculate Textboxes and sum in another textbox
But still (BTW salsa....he was NOT paying you a compliment!)...you SHOULD check input of your textboxes, regardless of you applications...many opportunities to do that...lostfocus/mouseup/keyup/button_click/etc, etc.
Also, although not in this case, if you are using textboxes with a zero in them, and you happen to be DIVIDING those values, you will get an error (crash) when you try to 'divide by zero'.