ProPascal INPUTs

Anything QL Software or Programming Related.
Post Reply
stevepoole
Super Gold Card
Posts: 713
Joined: Mon Nov 24, 2014 2:03 pm

ProPascal INPUTs

Post 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.


User avatar
tofro
Font of All Knowledge
Posts: 2699
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: ProPascal INPUTs

Post 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;


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
stevepoole
Super Gold Card
Posts: 713
Joined: Mon Nov 24, 2014 2:03 pm

Re: ProPascal INPUTs

Post 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.


User avatar
tofro
Font of All Knowledge
Posts: 2699
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: ProPascal INPUTs

Post 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


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
NormanDunbar
Forum Moderator
Posts: 2271
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: ProPascal INPUTs

Post 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.


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.
User avatar
tofro
Font of All Knowledge
Posts: 2699
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: ProPascal INPUTs

Post 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.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
NormanDunbar
Forum Moderator
Posts: 2271
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: ProPascal INPUTs

Post by NormanDunbar »

:D :D :D


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.
stevepoole
Super Gold Card
Posts: 713
Joined: Mon Nov 24, 2014 2:03 pm

Re: ProPascal INPUTs

Post 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.


Post Reply