Notifications
Clear all
[Closed] An update on a help file example
Jan 05, 2013 3:59 am
I came across this in the help file that i think is pretty useful…at least for what i need it for anyway.
rollout MicroListener "MicroListener"
(
edittext myEditText text:""
label theLabel "Ready."
on myEditText changed txt do
(
if txt != "" then
(
try
(
val = execute txt
theLabel.text = "You typed in "+ (val as string )
)
catch
theLabel.text = "Invalid Expression!"
)
else
theLabel.text = "Ready."
)
on myEditText entered txt do myEditText.text = ""
)
createDialog MicroListener 300 60
I'm wondering if someone could show/explain how to allow for spaces and possibly a certain sequence of numbers. The application that i would be using it for would limit the end user to typing in something like this:
1 0 0 3.14159
Four numbers with a space in between each.
I'm really trying to learn how to error proof my scripts so any help would be greatly appreciated.
2 Replies
Jan 05, 2013 3:59 am
You will probably need something like the filterString function:
--This line:
stringArr = filterString "1 0 0 3.14159" " "
--Results in:
#("1", "0", "0", "3.14159")
Then you could convert the string number values into floats/intergers like so:
for a in stringArr collect a as float
It seems odd to combine 4 numbers into a string though. Would it not make more sense to have 4 spinners in the UI? This would require a lot less error checking and handling.
Tim
Jan 05, 2013 3:59 am
I may actually go the spinner route. It is being written into a custom file format so i was going to take the resulting string and place it where i need it in the file.