Link to home
Start Free TrialLog in
Avatar of yaelie
yaelie

asked on

object not printable?

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.
Avatar of BigRat
BigRat
Flag of France image

Can you post the edclaration of "searchentry" please?
Avatar of yaelie
yaelie

ASKER

type
querytype=(name,date, departure, destination);

var
searchentry:querytype;

- and thanx for letting me know about it being posted twice
ASKER CERTIFIED SOLUTION
Avatar of BigRat
BigRat
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yaelie

ASKER

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
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
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.
Avatar of yaelie

ASKER

Thank you for the last comment!!! Thats all i needed to hear...cleared it all up. thanx for the help