Computer Science Canada

Make sure someone enters a string

Author:  chelsee [ Sat Dec 16, 2006 8:55 pm ]
Post subject:  Make sure someone enters a string

How do I make sure someone enters a string instead of an int or real?

Author:  Ultrahex [ Sat Dec 16, 2006 9:03 pm ]
Post subject: 

easiest way is read everything in as a String and check and then convert for using strintok ( s : string ) : boolean and check whether it is then convert and set as your integer variable.

Author:  mish [ Sat Dec 16, 2006 10:44 pm ]
Post subject: 

you would have to errortrap the user input. you would have to of course put declare variables first.

Author:  ericfourfour [ Sat Dec 16, 2006 10:45 pm ]
Post subject: 

You should actually use strrealok. This method will return true if a string can be converted to a real number. It will return false if it cannot.
code:
var number : string
get number
put number, " is "..
if not strrealok (number) then
    put "not" ..
end if
put " a number."

Author:  mish [ Sat Dec 16, 2006 10:47 pm ]
Post subject: 

LOLL whats a strrealok? o_O that looks an awful lot like an errortrap to me >.<

Author:  StealthArcher [ Sat Dec 16, 2006 10:53 pm ]
Post subject: 

Specifically these statements say "String OK", or in the case you refer to"String-Real OK" meaning that the given input can work with the stated conditions.

Author:  ericfourfour [ Sat Dec 16, 2006 11:49 pm ]
Post subject: 

mish wrote:
LOLL whats a strrealok? o_O that looks an awful lot like an errortrap to me >.<

F10. I think there is also a tutorial on it. And did you not read my post? I said exactly what it does.


: