Solved

object not printable?

Posted on 1998-11-30
7
308 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
Comment Utility
Can you post the edclaration of "searchentry" please?
0
 
LVL 1

Author Comment

by:yaelie
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:yaelie
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you for the last comment!!! Thats all i needed to hear...cleared it all up. thanx for the help
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

HOW TO: Connect to the VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere (HTML5 Web) Host Client 6.5, and perform a simple configuration task of adding a new VMFS 6 datastore.
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

16 Experts available now in Live!

Get 1:1 Help Now