checking input
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 46
- Joined: Sun Feb 14, 2016 9:08 am
checking input
How would I check the user input to make sure it is a number and not a letter or something else? I used if else statements to check to make sure the input is within the desired range, but I'm unsure of how to check for letters.
Re: checking input
Hi,
If you mean user entry into a field, put this into the field script
Now this is deceptively simple looking, but contains within it several key foundational tenets of LC. What do you think these might be?
Craig Newman
If you mean user entry into a field, put this into the field script
Code: Select all
on keyDown tKey
if tKey is in "0123456789." then pass keyDown
end keyDown
Craig Newman
-
- Posts: 46
- Joined: Sun Feb 14, 2016 9:08 am
Re: checking input
I have no idea. I know so little about LC that I wouldn't even know what to guess. I don't understand how this language doesn't have data types. It seems like this would limit the language so much.
-
- Posts: 46
- Joined: Sun Feb 14, 2016 9:08 am
Re: checking input
also, why do people prefix variables with letters? and how do you decide which letter to prefix. eg your example, tkey
Re: checking input
Here is Richard's excellent post on naming conventions
http://fourthworld.com/embassy/articles ... style.html
Simon
http://fourthworld.com/embassy/articles ... style.html
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: checking input
The data types are there; what's absent is the tedium of having to manually declare and coerce them.ethanCodes wrote:I don't understand how this language doesn't have data types. It seems like this would limit the language so much.
When we write:
put field 1 + field 2 into field 3
...LiveCode is smart enough to see that we're doing arithmetic so it automatically coerces the display strings from the field structures to numbers, and when we put the result into the third field it knows the field structure needs a string so it converts it for us.
Handy stuff, all taken care of for us so we can focus on crafting the user experience and leave the tedious bit counting to machines
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: checking input
Ethan.
What Richard said.
Another way to look at it is that LC types its variables based purely on context. If you try to: you will get a runTime error if horse does not contain a number. But you will not get a compileTime error, since the context has not yet been determined. I am not conversant with strongly typed languages, but would such a statement, or its syntactic equal, get even that far?
You have no idea, as Richard alluded to, how liberating this is. Maybe you will shortly. The question you must ask yourself is simple: can LC accomplish what you need? I guarantee it offers sufficient power and range.
Craig Newman
What Richard said.
Another way to look at it is that LC types its variables based purely on context. If you try to:
Code: Select all
add 3 to horse
You have no idea, as Richard alluded to, how liberating this is. Maybe you will shortly. The question you must ask yourself is simple: can LC accomplish what you need? I guarantee it offers sufficient power and range.
Craig Newman
Last edited by dunbarx on Sun Feb 21, 2016 4:10 am, edited 1 time in total.
Re: checking input
Due to LiveCode's English-like syntax you answered your own question:ethanCodes wrote:How would I check the user input to make sure it is a number
Code: Select all
if it is a number then...
See "is a" in the dictionary, there are many types you can check for.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 46
- Joined: Sun Feb 14, 2016 9:08 am
Re: checking input
Thank you for all the replies. You all helped me understand more of the different parts of LC. I'm getting a better understanding of it.