TextField - very newbie

Dear All,

I tried to write my first app in Xojo but I can’t. Please help what I mistake.
My code:
Dim TextField1 As String
Dim val As Integer
Dim sum As Integer
val = 5
sum = CDbl(TextField1) + val
MsgBox(str(sum))

I run it, write a number to the text field.
The result is “5” and in debug mode the “TextField1” is empty (does not contain any value)

Help me.
Thank you
Istvan

You need to use the property of text field, to get at its value.

sum=CDbl (textfield1.text)+val

I tried it but I got error:
Window1.PushButton1.Action, line 7: Type “String” has no member named “text”.

TextField is not a String, it is a TextField.

But TextField has a property called text which is a string

So

Dim s as String
s = TextField

Is wrong, but

Dim s as String
s = TextField.text

Is correct.

Next you need to understand the difference between text and numbers.

1 is a number
“1” is a string
A 1 typed in a TextField is a string, NOT a number.

Addition for numbers:

1 + 1 = 2

Addition for strings:

“A” + “B” = “AB”
“1” + “1” = “11”

So

1 + Textfield1.text

Is utter nonsense (what is this? Addition for numbers? Or for Strings?) and you’ll get an error.

To add the NUMERICAL value for the STRING in the TextField you’ll need to convert it into a NUMERICAL VALUE with

1 + Val(Textfield1.text). // now it is clearly an Addition for numbers

But you really should read the introduction first. That’s what it is for.

You don’t dim a textfield. You drag it onto the layout editor.

Looks like it would help you greatly to read Introduction to Programming

Thank you.

I read the introduction but I have to read it again :slight_smile:

If your very new, perhaps youtube can help you get where you want to be.
Xojo Youtube

Thank you.

Yes, I am very new.
I’m starting to develope for my company a not too difficult app.
I use osx, my colleagues use windows.
I don’t want to use virtualization for developing and the Xojo is the most likeable software for this project (however I would like to use my app on osx and tablets later).
I hope Xojo is the best choice