Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

object not printable?

Posted on 1998-11-30
7
Medium Priority
?
320 Views
Last Modified: 2010-04-16
procedure search;
begin      
    writeln('Please enter either name, date, departure or destination');
    readln(searchentry);
end;


searchentry is a predeclared type (since you cant case a string)....now when i try to run my program a get an error saying "object not printable"  pointing at the ")" after searchentry.

why is this happening and how can i fix it?
I'm not trying to print, just to read in a string.
0
Comment
Question by:yaelie
  • 3
  • 3
7 Comments
 
LVL 27

Expert Comment

by:BigRat
ID: 1216255
Can you post the edclaration of "searchentry" please?
0
 
LVL 1

Author Comment

by:yaelie
ID: 1216256
type
querytype=(name,date, departure, destination);

var
searchentry:querytype;

- and thanx for letting me know about it being posted twice
0
 
LVL 27

Accepted Solution

by:
BigRat earned 80 total points
ID: 1216257
Well yes, an enumerated type. Just as a matter of interest, what do you think the user ought to type in when your program does the Readln? And before you say "name" or "date" or "departure" or "destination" how do you think the compiler should process it?
An enumerated type cannot be "read-in" since it has no external representation.
   I admit the error message is crap but that's life. If you had actually put it in a write statement you would have got the correct error message. (You would also have had to change it to Ord(searchentry) - OK)
   The enumerated type is very nice but it does not allow for input error. I would suggest you do the following :-
var
   Option : Integer;

    Writeln('Option 1 for name');
    Writeln('Option 2 for date');
    Writeln('Option 3 for departure');
    Writeln('Option 4 for destination');
    repeat
       Write('Enter the option you require and press Enter:-');
       Readln(Option);
       if not((1<=Option) and (Option<=4)) then
          Writeln('Please enter a digit from 1 to 4 and press Enter');
   until (1<=Option) and (Option<=4);
   SearchEntry:=QueryType(Option);
   ...........
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
LVL 1

Author Comment

by:yaelie
ID: 1216258
ooh but there must be some other way...? otherwise ill just declare each as a char (for example if you want the name type in 'n') and use a case statement...and in that case i shouldnt have any problems....is there really no way to leave it declared the way i have it and read in to it?
also what i still dont understand is why is it even talking about printing?!
I'm sorry for all the questions....but thank you, the help is highly appreciated
0
 
LVL 2

Expert Comment

by:joe_h
ID: 1216259
There is always a way :) In this case, you can typecast the searchentry variable to a byte and read it in. In this case, user would enter 0 for name, 1 for date etc. You'd use something like:

var searchbyte: byte absolute searchentry; {lets you access searchentry as a byte}
.
 readln(searchbyte);
 case searchentry of
.

Works with Borland Pascal 7.0, should work on earlier versions too.

HTH, Joe
0
 
LVL 27

Expert Comment

by:BigRat
ID: 1216260
If you are not satisfied with an answer REJECT it so that others can try.
Last question first. You cannot Read nor Write variables of enumerated type without first converting them to an ordinal type (byte, integer or such). That's Pascal - go and complain to Prof. Wirth.
The compiler conplains about printing because the silly compiler writer did not take the bother of separating out two error messages from one. (I'm also very guilty of doing the same).
Lastly since you are going to have to read in something which gets converted to teh type you want, it is ALWAYS a good idea to inform the user about EXACTLY you expect him to type in. Your proposal of using the first letter is generally acceptable provided that it is unique. Here you have Date and Destination, so a "d" is not unique. Furthermore entering simple numbers is extensible - you just add a new number, and one can do it from the numeric pad which sames making tpyign mitsakse - if you see what I mean.
0
 
LVL 1

Author Comment

by:yaelie
ID: 1216261
Thank you for the last comment!!! Thats all i needed to hear...cleared it all up. thanx for the help
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
Steps to fix error: “Couldn’t mount the database that you specified. Specified database: HU-DB; Error code: An Active Manager operation fail”
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

926 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