Page 1 of 1
value() function for invalid expressions
Posted: Thu Feb 13, 2014 1:33 pm
by acwilson96
I am creating a simple maths game and I want the user to be able to type in a sum using numbers and operations and brackets but I cannot find a way of letting them use brackets without the possibility of error, for example when they enter a sum, e.g. 9+2, if they have brackets like this: (9+2( then when I use
it wont run as the entered input is not of correct syntax. Is there any way of having the program ignore it if it cannot be 'assigned a value'.
Re: value() function for invalid expressions
Posted: Thu Feb 13, 2014 1:41 pm
by Klaus
Hi acwilson96,
you can use a TRY structure to catch eventual errors!
Example:
Code: Select all
...
try
## In case of success:
put value(field "userAnswerField") into fld "UserResult"
## catch eventual error:
catch errornum
anser "Wrong input! Try again."
## or do whatever you want in this case of erratic user input.
end try
...
This will erm. TRY to put the value of the text field into another field
and answer a dialog if it does not succeed!
Best
Klaus
Re: value() function for invalid expressions
Posted: Thu Feb 13, 2014 4:26 pm
by dunbarx
Hi.
What Klaus said.
Not brackets, "[]". Parentheses. "()", right?
Another way, if you like to assemble houses of cards like I do, is to validate the string completely. You said you always have parentheses, so you can make sure that there is a single open paren, "(", and that a single close paren ")" follows it. This can be done with such tools as the offset function and perhaps the itemdelimiter. Can you do this sort of thing? If not, write back, but it would be a great exercise in fooling around with LC text and chunking.
Craig Newman
Re: value() function for invalid expressions
Posted: Thu Feb 13, 2014 9:19 pm
by acwilson96
Thanks for the replies I will try them tomorrow when I am back at my PC and yes I meant parentheses! I will look into "itemdelimiter" and see if I can get anywhere and will post back the results!