Woes of a beginner

I recently did a course on VB.net (since no xojo courses are available in my country) and now i want to repeat my exercises in Xojo.
I’m already stuck on exercise one : adding to values from 2 textfields and showing result in a 3rd textfield.

In VB.net it’s very easy : txtbox3.text = CInt(txtbox1.text) + CInt(txtbox2.text)
but in xojo i can’t seem to find the correct syntax to repeat this simple exercise.
i’ve tried following code, even declaring variables…

//TextField3.text = Ctype(TextField1.text, Integer) + (TextField2.text, Integer)
or
//dim a as integer = TextField1.text
//dim b as integer = TextField2.Text
//TextField3.text = a + b
or
//TextField3.Text = integer.FromText(TextField1.Text) + integer.FromText(TextField2.Text)
or
//TextField3.Text = val(TextField1.text) + val(TextField2.Text)
or
dim a, b, x as string
a = Cstr(textfield1.text)
b = Cstr(textfield2.text)
x = Cstr(TextField3.Text)
textfield3.text=Cstr(x)

In the last one the code actually runs but i don’t get a result.
Can anyone advise?
Thanks !

Var sum as integer

sum = TextField1.text.val + TextField2.Text.val
TextField3.text = sum.ToString

TextField3.Value = Str( TextField1.Value.ToDouble + TextField2.Value.ToDouble)

http://documentation.xojo.com/api/text/str.html
http://documentation.xojo.com/api/data_types/string.html.ToDouble

:slight_smile:

@Tim: I get a lot of errors, changed var to dim just to make sure, but still
Window1.PushButton1.Action, line 4
Type “Integer” has no member named “ToString”
TextField3.text = sum.ToString
Window1.PushButton1.Action, line 4
Type mismatch error. Expected String, but got Int32
TextField3.text = sum.ToString

@Sascha: Window1.PushButton1.Action, line 3
Type “TextField” has no member named “Value”
TextField3.value = Str( TextField1.Value.ToDouble + TextField2.Value.ToDouble)
Window1.PushButton1.Action, line 3
Type “Int32” has no member named “ToDouble”
TextField3.value = Str( TextField1.Value.ToDouble + TextField2.Value.ToDouble)
for al textfields.

I tried changing code here as well but no avail
I’m working on a mac, maybe it’s a configuration issue?
As i read both your codes I think it should work?

Just use the latest Xojo Version. Value and ToDouble have been implemented with API 2.0.

in an older Xojo, you would write:

TextField3.Text = Str( CDbl( TextField1.Text ) + CDbl( TextField2.Text ) )

http://documentation.xojo.com/api/deprecated/cdbl.html

it’s the latest version :wink:

i found a solution i think : TextField3.Text = CStr(Val(TextField1.text) + Val(TextField2.Text))
now i actually get a result!
Thanks for your input!