Solved

Problems with writeln and readln I'm using records

Posted on 1999-01-08
6
362 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
We have put together a white paper that aims to explain how MSPs can both improve their offering and ease the pain of after-hours service by: -Suggesting changes to workflow -Indicating how to rework policy to suit your team -Providing ConnectW…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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