Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 366
  • Last Modified:

Problems with writeln and readln I'm using records

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
cocj
Asked:
cocj
1 Solution
 
vikiingCommented:
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
 
scrapdogCommented:
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
 
pobwestCommented:
in addition.. if you have used a read command before using a readln it sometimes dosen't work...i've found
0
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 
flobeckerCommented:
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
 
viktornetCommented:
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
 
viktornetCommented:
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now