?
Solved

object not printable?

Posted on 1998-11-30
7
Medium Priority
?
318 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 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
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

 
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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
On September 18, Experts Exchange launched the first installment of the Help Bell, a new feature for Premium Members, Team Accounts, and Qualified Experts. The Help Bell will serve as an additional tool to help teams increase question visibility.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

719 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