Page 1 of 1
ProPascal INPUTs
Posted: Thu Aug 27, 2020 8:16 am
by stevepoole
Hi All,
After transcoding a dozen or so SuperBasic programs into ProPascal, I am now feeling much more at ease with the latter language.
I can error-trap character and integer input, but not string-type...
The main difficulty is to trap the dreaded null entry !
Has anyone overcome this hurdle ?
Regards,
Steve.
Re: ProPascal INPUTs
Posted: Thu Aug 27, 2020 9:41 am
by tofro
Why not simply check the string that was input for a "Length()" of 0?
Code: Select all
valid := FALSE;
REPEAT
ReadLn (Input, inputLine)
valid := (Length (inputLine) > 0);
UNTIL valid;
Re: ProPascal INPUTs
Posted: Fri Aug 28, 2020 3:37 pm
by stevepoole
Hi Tofro,
Many thanks. Yes, your solution does work for strings.
I still can't see any way to avoid people entering a null string when an integer or real value is requested...
If ProPascal had a 'power' function, I could do it by adding powers of ten, but there is none...
Do Pascal programmers need to write their own libraries of core routines ?
Best Wishes,
Steve.
Re: ProPascal INPUTs
Posted: Fri Aug 28, 2020 4:56 pm
by tofro
stevepoole wrote:
Do Pascal programmers need to write their own libraries of core routines ?
Well,
all Programmers in all languages that intend to lift their programs from fool-proof to (somewhat) damn-fool-proof, will generally only allow string input - then, in the program, see if this can be converted safely to a number if they actually want one.
Tobias
Re: ProPascal INPUTs
Posted: Fri Aug 28, 2020 5:18 pm
by NormanDunbar
Norm's second law of computing:
Whenever you write fool proof code, the universe invents a bigger fool!
Norm's first law, for those wondering:
The complexity of programs doubles every 18 months thus negating all the benefits of Moore's Law.
Cheers,
Norm.
Re: ProPascal INPUTs
Posted: Fri Aug 28, 2020 5:52 pm
by tofro
NormanDunbar wrote:Norm's second law of computing:
Whenever you write fool proof code, the universe invents a bigger fool!
I'm with you on that, that's the reason for the
somewhat damn-fool-proof.
Re: ProPascal INPUTs
Posted: Fri Aug 28, 2020 7:42 pm
by NormanDunbar
Re: ProPascal INPUTs
Posted: Sat Aug 29, 2020 11:22 pm
by stevepoole
Hi Guys,
Without going into details, Propascal string 'lengths' are no good for dealing with numeric inputs.
Propascal arrays are not much use either...
After a lot of experimenting, I finally had to resort to using Tofro's INKEY function to construct my own integer INPUT routine.
Programs are now watertight, but ProPascal is far from being as easy to prototype with as QL Basics !
Many thanks again for the INKEY snippets.
Steve.