Adding Textboxes Together

Looking for a way to add 2 numeric values of 2 textboxes together.

Thanks Shane.

[code] Dim c as integer

c = cdbl(TextField1.text) + cdbl(TextField2.text)

msgbox str©[/code]

No error checking or anything but gives you a starting point :slight_smile:

How do I make the totals automatically display in a 3rd textfield, thanks

str(c) is a string. See http://documentation.xojo.com/index.php/TextField

Place the following code in the “Event Handler” “TextChange” for “TextField1” and “TextField2”.

TextField3.Text = Str( cdbl(TextField1.text) + cdbl(TextField2.text))

I have tried using this code, but the result in mensfront always comes up as 0

dim mens1 as double = cdbl(mens1.text) dim mens2 as double = cdbl(mens2.text) mensfront.text = str(mens1 + mens2)

[quote=110825:@Shane Rampling]I have tried using this code, but the result in mensfront always comes up as 0

dim mens1 as double = cdbl(mens1.text) dim mens2 as double = cdbl(mens2.text) mensfront.text = str(mens1 + mens2)[/quote]
Where is this code located?

In the keydown event

The “TextChange” event handler mentioned above works fine. There is no interest in the “KeyDown” as there is no need to take any action when any key has been pressed in the text field. Instead the interest is in the “TextChange” when it has already taken place.

Thanks Syed, works fine now. Cheers Shane

You are welcome.

Sequence of events of a text field can be recorded and observed by adding a new dummy TextField4. Then add the following lines of code as the first line in each of the indicated events of TextField1.

// TextChange
TextField4.text = TextField4.text + " | " + "TF1.TC"

// KeyUp
TextField4.text = TextField4.text + " | " + "TF1.KU"

// KeyDown
TextField4.text = TextField4.text + " | " + "TF1.KD"

Now as any key is pressed in TextField1, then the TextField4 should show the sequence of events for TextField1 related to the key just pressed in TextField1. Other events can be added and the required code added in each event as needed to see the sequence. All this can be done with breakpoints as well. However the above presents a visible sequence.

You cannot have a Variable with name mens1 and a Control with name mens1

dim mens1 as double = cdbl(mens1.text) dim mens2 as double = cdbl(mens2.text) mensfront.text = str(mens1 + mens2)

Try

dim mens1 as double = cdbl(mensA1.text) dim mens2 as double = cdbl(mensA2.text) mensfront.text = str(mens1 + mens2)

And both events : Keydown and textChange fire after each letter you type in.

If you put it in the keydown, in a Condition like:

If key=chr(13) or key=chr(3) then

end if

it will happen only, if return or enter are pressed