Skip to main content
Inspiring
January 30, 2008
Answered

text field datatype

  • January 30, 2008
  • 3 replies
  • 320 views
I am trying to capture a number from a text field and then perform a calculation on it. It is for navigation so a person can type in what screen they want to go to. However, it always looks at the value as a string and I need it to be a number to do the calculation. Can I change the datatype of the textfield or a variable?
This topic has been closed for replies.
Correct answer
change data type of your string to integer, so line 2 becomes:

jumpVar = 10 * int(jump_txt.text);

3 replies

ski_geekAuthor
Inspiring
January 30, 2008
Awesome, thank you to both!
Participating Frequently
January 30, 2008
Yes, this is known as "casting" and can be done because of the close relationship between this format: "123" and 123. This does not affect the text field as it does not convert the origional value, it only looks at the value in the string as if it were a number, or in this case an integer. As you know only a positive integer should be entered by the user, it would be better to use:

jumpVar = 10 * uint(jump_txt.text);

as this would change "-123" to simply 123.
Correct answer
January 30, 2008
change data type of your string to integer, so line 2 becomes:

jumpVar = 10 * int(jump_txt.text);