Recent

Author Topic: Readln; doesn't stop program from exiting  (Read 5114 times)

RNBW

  • New member
  • *
  • Posts: 7
Readln; doesn't stop program from exiting
« on: February 07, 2017, 01:26:51 pm »
It seems to work elsewhere, and worked before I put in the input line, but now after I have entered the number the program closes. 

Also, is there any way to stop 0 being displayed for the variable ns before entering its value?

Code: Pascal  [Select][+][-]
  1. program SimpleBeam_Dev01_01;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Classes;
  10.  
  11.  
  12. var
  13.   ns,nl: Integer;
  14.  
  15. begin
  16.    Writeln('SINGLE SPAN SIMPLY SUPPORTED BEAM PROGRAM');
  17.    Writeln;
  18.    Write('ENTER NUMBER OF SECTIONS TO BE CONSIDERED ON THE BEAM: ',ns);
  19.  
  20.    Readln;
  21. end.
  22.  


Any help will be appreciated.

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Readln; doesn't stop program from exiting
« Reply #1 on: February 07, 2017, 01:31:21 pm »
How can I explain this without giving away too much :D

What do you think this line does?
Code: Pascal  [Select][+][-]
  1. Write('ENTER NUMBER OF SECTIONS TO BE CONSIDERED ON THE BEAM: ',ns);


And what do you think this line does?
Code: Pascal  [Select][+][-]
  1. Readln;


I don't see anywhere where you ask for input for the variable ns.
I see you outputting ns to the screen.
And I see you asking for the user to enter a (any) line.
But nothing about inputting ns.

Handoko

  • Hero Member
  • *****
  • Posts: 5154
  • My goal: build my own game engine using Lazarus
Re: Readln; doesn't stop program from exiting
« Reply #2 on: February 07, 2017, 02:43:42 pm »
Well, some more hints for  RNBW:

ReadLn need parameter.
 ;D

http://www.freepascal.org/docs-html/rtl/system/readln.html

--- edited:
Actually it needs 2 ReadLn: one with parameter and (the last) one without parameter.
« Last Edit: February 07, 2017, 03:13:38 pm by Handoko »

RNBW

  • New member
  • *
  • Posts: 7
Re: Readln; doesn't stop program from exiting
« Reply #3 on: February 07, 2017, 04:46:21 pm »
Thank you rvk and Handoko.

I completely misunderstood the Writeln('...', ns) in thinking that the ns would input the value, not display it.  Similar misunderstanding with Readln.

I've got it now and the code works fine.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Readln; doesn't stop program from exiting
« Reply #4 on: February 07, 2017, 04:55:30 pm »
ReadLn need parameter.
 
Yes, for it to be meanyningful it needs to be ReadLn(ns).
Readln always expects a #10 on linux, #13#10 on Windows, Dos, OS/2) as the last Keyboard entry for it to continue.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Handoko

  • Hero Member
  • *****
  • Posts: 5154
  • My goal: build my own game engine using Lazarus
Re: Readln; doesn't stop program from exiting
« Reply #5 on: February 07, 2017, 05:00:43 pm »
@RNBW:

Glad to know you solved it.

Here are some good tutorials to improve your Pascal skill:
http://lazplanet.blogspot.co.id/
https://www.devstructor.com/
https://www.tutorialspoint.com/pascal/index.htm
http://wiki.freepascal.org/Lazarus_Documentation#Lazarus_and_Pascal_Tutorials

@Thaddy:

Thank you for the more detail info but I'm afraid the TS can't understand. But he sure will someday.
« Last Edit: February 07, 2017, 05:05:20 pm by Handoko »

RNBW

  • New member
  • *
  • Posts: 7
Re: Readln; doesn't stop program from exiting
« Reply #6 on: February 07, 2017, 08:57:25 pm »
Thank you Handoko for the list of tutorials.  I've already picked up a couple of them, but I'll have a look at the others.

 

TinyPortal © 2005-2018