copy textbox's content in a variable

sorry but i have a simple problem. i need to copy the textbox’s content in a variable with corona sdk for an android app. help me please  :frowning:

Can’t you get it with textbox.text? Or is it write only?

i don’t know because if i do in that way it give an error. i need this because i want to take the values of text box to do a mathematic operation,infact i want to build an app that solve electrical circuits.

Ah, ok.

So then why don’t you devide the data from the text?

Save all data needed in a table and let the textbox use the table’s data.

So you have always access to the data.

can you give me an example?please…

I meant something like this:

[LUA]

local text_table = {[“value_1”] = 5,}

local textfield = display.newText(text_table[“value_1”], 32, native.systemFont)

[/LUA]

And when you want to do an operation you do this:

[LUA]

text_table[“value_1”] = text_table[“value_1”] + 5

textfield.text = text_table[“value_1”]

[/LUA]

Or wasn’t that what you want to do and I got it all wrong?

no, I want to enter a value using the keyboard in a text box, then i want copy that value in a variable to do mathematical operations. in fact i want that the user can enter, for example, the resistor’s value and intensity’s value and then i give back the voltage’s value. sorry for my bad english but i am italian.  so thank you for your attention

Ah, now I understand. So you use native.newTextField or native.neyTextBox?

Then it’s pretty easy, you get the entered Text, as I mentioned before, with yourtextbox.text.

But then you get a string and you need a number for math. For that you use tonumber(string).

For example:

[LUA]

local text = yourTextfield.text

local value = tonumber(text)

if value then

   newvalue = value * 2

end

[/LUA]

Hope that will help you.

i am so stupid, but if i write this code 

local textBox = native.newTextBox(100, 100, 280, 70 )

local text = textBox.text

local value = tonumber(text)

if value then

   newvalue = value * 2

end

local testo=display.newText(newvalue,200,200,native.systemFont,40)

it give back an error     --> bad argument#1 to ‘new text’ (string expected,got nill)

then in this way i don’t solve that problem but i dont know the reason ( i add the last line because i want to try to visualize the newvalue’s content)

You know, I only wrote pseudo code. You can’t grab the text from a textfield that is empty.

Before that someone has to type something in right? :wink:

Did you read the doc entry about native textfields? You can find it here:

http://docs.coronalabs.com/api/library/native/newTextField.html

I don’t really know how dto help you, cause I don’t know what you already did. Can you already put text into that textfield via the keyboard or at which point are you?

i know this page… ok I try to explain in a better way

1 i need to a text box to insert a value with keyboard, but it is not a problem because it’s so easy to build a textbox

2 after this, i want take the content of that textbox and copy it in a variable,for example with a button event

3 at the end i want to visualize that content in another line…such as in a local testo=display.newText…do you understand?

Can’t you get it with textbox.text? Or is it write only?

i don’t know because if i do in that way it give an error. i need this because i want to take the values of text box to do a mathematic operation,infact i want to build an app that solve electrical circuits.

Ah, ok.

So then why don’t you devide the data from the text?

Save all data needed in a table and let the textbox use the table’s data.

So you have always access to the data.

can you give me an example?please…

I meant something like this:

[LUA]

local text_table = {[“value_1”] = 5,}

local textfield = display.newText(text_table[“value_1”], 32, native.systemFont)

[/LUA]

And when you want to do an operation you do this:

[LUA]

text_table[“value_1”] = text_table[“value_1”] + 5

textfield.text = text_table[“value_1”]

[/LUA]

Or wasn’t that what you want to do and I got it all wrong?

no, I want to enter a value using the keyboard in a text box, then i want copy that value in a variable to do mathematical operations. in fact i want that the user can enter, for example, the resistor’s value and intensity’s value and then i give back the voltage’s value. sorry for my bad english but i am italian.  so thank you for your attention

Ah, now I understand. So you use native.newTextField or native.neyTextBox?

Then it’s pretty easy, you get the entered Text, as I mentioned before, with yourtextbox.text.

But then you get a string and you need a number for math. For that you use tonumber(string).

For example:

[LUA]

local text = yourTextfield.text

local value = tonumber(text)

if value then

   newvalue = value * 2

end

[/LUA]

Hope that will help you.

i am so stupid, but if i write this code 

local textBox = native.newTextBox(100, 100, 280, 70 )

local text = textBox.text

local value = tonumber(text)

if value then

   newvalue = value * 2

end

local testo=display.newText(newvalue,200,200,native.systemFont,40)

it give back an error     --> bad argument#1 to ‘new text’ (string expected,got nill)

then in this way i don’t solve that problem but i dont know the reason ( i add the last line because i want to try to visualize the newvalue’s content)

You know, I only wrote pseudo code. You can’t grab the text from a textfield that is empty.

Before that someone has to type something in right? :wink:

Did you read the doc entry about native textfields? You can find it here:

http://docs.coronalabs.com/api/library/native/newTextField.html

I don’t really know how dto help you, cause I don’t know what you already did. Can you already put text into that textfield via the keyboard or at which point are you?