Solved

object not printable?

Posted on 1998-11-30
7
316 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
[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
  • 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 20 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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

First of all let me say that the only language that I speak is English, but in answering questions here I often come across people whose English skills are not the best and I’d like to be able to communicate better with them, and the following descr…
Choosing a core focus or particular set of features and options can be tough. To help out, we’re going to highlight a handful of things your business needs on one of your social media pages. In other words, if one of these is missing, you should imp…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

615 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