Solved

Problems with writeln and readln I'm using records

Posted on 1999-01-08
6
359 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Cloud-based technologies and services will continue to grow in popularity in 2017 thanks to the simple, scalable and cost-effective solutions they deliver. Here are three areas where cloud adoption is poised to really take off.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

911 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

19 Experts available now in Live!

Get 1:1 Help Now