
SuperBASIC function for type validation
- grafvonb
- Bent Pin Expansion Port
- Posts: 81
- Joined: Sat Jan 05, 2019 7:54 am
- Location: Frankfurt/Germany
SuperBASIC function for type validation
I can't find it
. How to check if a non-numeric of empty data has been entered in a numeric field (or vice versa) using SuperBASIC?

Loving QL & ZX Spectrum & Amiga...
Re: SuperBASIC function for type validation
Hi,
Are you looking for a function/procedure in Superbasic to ensure only numeric input? If so there are a few examples in QL World Magazine.
In QLWorld 1986 November 1986 page 36 there is a Superbasic function. The magazine can be downloaded from Dilwyn Jones site here http://www.dilwyn.me.uk/mags/qluserworl ... 986-11.pdf
There was also a calculator project later on perhaps in 1988.
Cheers
Are you looking for a function/procedure in Superbasic to ensure only numeric input? If so there are a few examples in QL World Magazine.
In QLWorld 1986 November 1986 page 36 there is a Superbasic function. The magazine can be downloaded from Dilwyn Jones site here http://www.dilwyn.me.uk/mags/qluserworl ... 986-11.pdf
There was also a calculator project later on perhaps in 1988.
Cheers
Re: SuperBASIC function for type validation
There are quite some ways to skin that cat:
The S*Basic reference manual has another nice example of a "safe input" routine in its INPUT section that doesn't need any Toolkit.
With some "modern" toolkits/compilers you can make this significantly simpler.
WHEN ERROR: Catch the "bad parameter" error on coercion and repeat input
DIY Toolkit has some functions (CHECKF and CHECK%) that test whether a string can safely be converted to a number.
Turbo Toolkit has functions EDITF and EDIT%, which will reject anything that is not a proper number.
The S*Basic reference manual has another nice example of a "safe input" routine in its INPUT section that doesn't need any Toolkit.
With some "modern" toolkits/compilers you can make this significantly simpler.
WHEN ERROR: Catch the "bad parameter" error on coercion and repeat input
DIY Toolkit has some functions (CHECKF and CHECK%) that test whether a string can safely be converted to a number.
Turbo Toolkit has functions EDITF and EDIT%, which will reject anything that is not a proper number.
ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
- NormanDunbar
- Forum Moderator
- Posts: 2470
- Joined: Tue Dec 14, 2010 9:04 am
- Location: Buckie, Scotland
- Contact:
Re: SuperBASIC function for type validation
Code: Select all
1000 WHEN ERRor
1010 PRINT "That was not a number!"
1020 CONTINUE
1030 END WHEN
1040 :
1050 :
2000 REPeat loop
2010 INPUT "Please enter a number: "; num$
2020 num = num$
2030 PRINT "Your number was: " & num
2040 END REPeat loop
Number formats such as "1e6" don't fire the error handler, but return 1e6 as the value. Floating point numbers are happily accepted as well.
HTH
Cheers,
Norm.
Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
- NormanDunbar
- Forum Moderator
- Posts: 2470
- Joined: Tue Dec 14, 2010 9:04 am
- Location: Buckie, Scotland
- Contact:
Re: SuperBASIC function for type validation
Beaten, once again, by tofro. 

Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Re: SuperBASIC function for type validation
No worries, Norm, I'll hold back next timeNormanDunbar wrote:Beaten, once again, by tofro.

At least you've presented an example that works in SBASIC - I haven't.
Tobias
ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
- NormanDunbar
- Forum Moderator
- Posts: 2470
- Joined: Tue Dec 14, 2010 9:04 am
- Location: Buckie, Scotland
- Contact:
Re: SuperBASIC function for type validation
Nah, don't hold back, I have been known to be wrong! Just ask my wife!
Cheers,
Norm.
Cheers,
Norm.
Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
- grafvonb
- Bent Pin Expansion Port
- Posts: 81
- Joined: Sat Jan 05, 2019 7:54 am
- Location: Frankfurt/Germany
Re: SuperBASIC function for type validation
Many thanks guys, I have now a lot of stuff to check!
Loving QL & ZX Spectrum & Amiga...
Re: SuperBASIC function for type validation
Ive never been fond of WHEN ERRor. I just use it as a last resort. Perhaps this is because of all the problems the various implementation had in their early incarnations. But even now there are tricky issues to beware of. Viz:
The problem being demonstrated is that the next error encountered will (probably unintentionally) trip the same WHEN ERRor clause. Ones needs to remember to turn WHEN ERRor off:
Code: Select all
1000 WHEN ERRor
1010 PRINT "That was not a number!"
1020 CONTINUE
1030 END WHEN
1040 :
1050 :
2000 REPeat loop
2010 INPUT "Please enter a number: "; num$
2015 IF num$ = '': EXIT loop
2020 num = num$
2030 PRINT "Your number was: " & num
2040 END REPeat loop
2050 :
2060 num = 5/0: REMark Just a trivial example
Code: Select all
1000 WHEN ERRor
1010 PRINT "That was not a number!"
1020 CONTINUE
1030 END WHEN
1040 :
1050 :
2000 REPeat loop
2010 INPUT "Please enter a number: "; num$
2015 IF num$ = '': EXIT loop
2020 num = num$
2030 PRINT "Your number was: " & num
2040 END REPeat loop
2050 :
2052 :
2055 WHEN ERRor
2057 END WHEN: REMark WHEN ERR turned off
2058 :
2060 num = 5/0
Per
I love long walks, especially when they are taken by people who annoy me.
- Fred Allen
I love long walks, especially when they are taken by people who annoy me.
- Fred Allen
- NormanDunbar
- Forum Moderator
- Posts: 2470
- Joined: Tue Dec 14, 2010 9:04 am
- Location: Buckie, Scotland
- Contact:
Re: SuperBASIC function for type validation
Hi Per,
good point, well made. Thanks.
Cheers,
Norm.
good point, well made. Thanks.
Cheers,
Norm.
Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.