Solved

Problems with writeln and readln I'm using records

Posted on 1999-01-08
6
358 Views
Last Modified: 2010-04-16
When I use this procedure it won't execute the line,
  "Readln (Table[lPIcount].Init);"
(This is 11 lines after the first BEGIN)
The only work around I know is wheres the writeln and readln code is placed in twice.  Then on the second occurence of readln it picks it up.  So the output looks as follows:

  Please enter players initials
  Please enter players initials
  (Cursor left here before any input)

Here's a copy of the whole procedure:

PROCEDURE PlayerInformation(VAR lPIPlayerFree : Player);

VAR
  lPIcount:INTEGER;
  lPIfinished:BOOLEAN;
  lcheckname:INTEGER;

BEGIN
  lPIcount:= 1;
  lPIfinished:=FALSE;
  WHILE (lPIcount<=20) AND NOT lPIfinished DO
  BEGIN        
  IF NOT lPIPlayerFree[lPIcount] THEN        {If player no. free, program continues}
    BEGIN
        lPIPlayerFree[lPIcount]:= TRUE;    {Player number no longer available}
        Table[lPIcount].PlayerNo:=lPIcount;
        Writeln('Please enter players initials');
        Readln (Table[lPIcount].Init);
        Writeln('Please enter players initials');
        Readln (Table[lPIcount].Init);
        {Writeln('Please enter players surname');
        Readln (Table[lPIcount].Surname); {Enters the surname into the appropriate record}
        {Writeln(Table[lPIcount].Surname); {Displays it here!}
        {Writeln('Please enter players surname');  }
       
        {Enters the initials into the appropriate record}
        {Writeln(Table[lPIcount].Init); {Used for debugging!}
        FOR lcheckname:=1 TO 20 DO

        IF table[lPIcount].Init=table[lcheckname].Init THEN
           IF table[lPIcount].Surname=table[lcheckname].Surname THEN
               IF lPIcount<>lcheckname THEN
                 BEGIN
                   Writeln('Sorry, that name has already been entered');
                   Readkey;
                   lPIplayerfree[lPIcount]:=FALSE;
                 END;

        BEGIN
          Writeln('Player ', table[lPIcount].PlayerNo);
          Writeln('Initial:',table[lPIcount].Init);
          Writeln('Surname:',table[lPIcount].Surname);
          Writeln('Please press ENTER to return to the main menu');
          Readkey;
          lPIfinished:= TRUE
        END;
    END; {BEGIN}
    INC (lPIcount)
END;   {BEGIN}

END; {PlayerInformation}
0
Comment
Question by:cocj
6 Comments
 
LVL 3

Expert Comment

by:vikiing
ID: 1216871
The problem you have is that the first Readln doesn't pick up the value entered at keyboard ?

If it's so, check if, when Readln executes, keyboard is really empty. It's possible some garbage remains at keyboard buffer, messing the read operation.

To ensure keyboard is empty, you can do the following:

  { "ch" is a char-type variable }
  While KeyPressed do ch:=ReadKey;


0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1216872
addition to vikiing's comment:  make sure you include "uses crt" at the top of the program if you are going to use keypressed and readkey.
0
 

Expert Comment

by:pobwest
ID: 1216873
in addition.. if you have used a read command before using a readln it sometimes dosen't work...i've found
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Expert Comment

by:flobecker
ID: 1216874
Please,
copy the part where the type Player and the Array Table is beeing defined.
What compiler are you using?
Maybe (under windows-compilers?)
 Table[lPIcount].Init
is interpreted as any (no idea what kind of - maybe some memory stuff) INITialisation of the variable. Check out, if INIT is a reserved keyword ! Or rename "init" to "initials" or so (just an idea...)


0
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
ID: 1216875
Here is s snippet from your code...

{Writeln('Please enter players surname');
Readln (Table[lPIcount].Surname); {Enters the surname into the appropriate record}
{Writeln(Table[lPIcount].Surname); {Displays it here!}
{Writeln('Please enter players surname');  }
{Enters the initials into the appropriate record}
{Writeln(Table[lPIcount].Init); {Used for debugging!}

OK do you see what I see??

What are those nested comments doing there?? When you remove them it should look like this

Writeln('Please enter players surname');
Readln (Table[lPIcount].Surname); {Enters the surname into the appropriate record}
Writeln(Table[lPIcount].Surname); {Displays it here!}
Writeln('Please enter players surname'); {Enters the initials into the appropriate record}
Writeln(Table[lPIcount].Init); {Used for debugging!}


Something different huh?

Try com[piling it now and it would work for sure :))

-Viktor
--Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1216876
The problem was that you have commented out one of the line just by mistake and you thought that it wasn't picking it up.... Now after you uncomment that just erase the second readln() and you are all set....

-Viktor
--Ivanov
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
A procedure for exporting installed hotfix details of remote computers using powershell
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now