Solved

Problems with writeln and readln I'm using records

Posted on 1999-01-08
6
363 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
Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

 

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Today’s effective marketing is about coming down to the customers’ level and engaging in a whole new way. A text message is one of the most effective and influential ways that you can engage your customers. Here are eight ways that you can utilize t…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 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