pascal display error

2

Comments

  • To make sure you always run in 80x50 mode, use this at the start of your main section:

    [code]
    TextMode(c80 + Font8x8);
    [/code]

    This will make sure you are in 50 lines mode.
  • thanks it worked!

  • I have another problem.... when I enter a record it is stored. when i enter another record when the program is still running it stores but the first record that was created is deleted... the code is still the same as i first gave in the previous post.

    please help me....


    thanks devindra
  • In [b]Procedure storereservation[/b] you [b]reset[/b] and [b]close[/b] the file every time you store a reservation. By default the file pointer points to record zero immediately after [b]reset[/b]. To add an additional record you need to position the pointer to the end of the file.

    [code]
    reset(reserve);
    [red]{
    your code here
    }
    seek(reserve,filesize(reserve)) ; { find end of file }[/red]
    write(reserve,reservationinfo);
    close(reserve);
    [/code]

  • thanks it worked....
    i have a problem with the printer function in my program. nothing is happening when i choose to print..
    below is the updated code:

    Program SandsRegencyReservations(INPUT,OUTPUT);
    Uses dos,crt,Printer;

    CONST
    dates:array[1..12] of integer= (31,28,31,30,31,30,31,31,31,31,30,31);

    TYPE
    reservations=RECORD
    dob,phone:string;
    age:integer;
    country,city,address,email,firstname,lastname,comments:string;
    checkinday,checkoutday,checkinmonth,checkoutmonth,typeofroom:integer;
    amountcharge:integer;
    END;

    VAR
    count:byte;
    Y:string;
    textfile:text;
    reserve:FILE OF reservations;
    choice:integer;
    Year,Month,Day,Weekday:word;
    Hour,Minute,Second,Hundredths:word;

    Procedure openfile;
    BEGIN
    assign(textfile,'text.txt');
    reset(textfile);
    assign(reserve,'RESERVED.dat');

    END;

    Procedure currency;
    VAR
    money:real;
    converted:real;
    choice:integer;

    BEGIN
    clrscr;
    textcolor(yellow);
    gotoxy(2,2);
    Writeln('Please choose the currencies to convert between.');
    textcolor(white);
    gotoxy(2,4);
    Writeln('1) USD TO BDS');
    gotoxy(2,6);
    Writeln('2) EUR TO BDS');
    gotoxy(2,8);
    Writeln('3) TTD TO BDS');
    gotoxy(2,10);
    Writeln('4) GYD TO BDS');
    gotoxy(2,12);
    Writeln('5) JMD TO BDS');
    gotoxy(2,14);
    textcolor(yellow);
    Writeln('Please enter your choice:');
    gotoxy(2,15);
    textcolor(white);
    readln( choice);
    clrscr;
    Writeln;
    CASE choice of
    1: Begin
    Writeln(' Please enter the amount to be converted from USD to BDS:');
    readln( money);

    converted:=money*2;
    gotoxy(1,4);
    Writeln('The amount in BDS is $',converted:2:2);
    end;

    2:BEGIN
    Writeln(' Please enter the amount to be converted from EUR to BDS:');
    readln( money);

    converted:=money*2.5;
    gotoxy(1,4);
    Writeln('The amount in BDS is $',converted:2:2);
    end;

    3:BEGIN
    Writeln(' Please enter the amount to be converted from TTD to BDS:');
    readln( money);

    converted:=money*0.31;
    gotoxy(1,4);
    Writeln('The amount in BDS is $',converted:2:2);
    end;

    4:BEGIN
    Writeln(' Please enter the amount to be converted from GYD to BDS:');
    readln( money);

    converted:=money*0.0097;
    gotoxy(1,4);
    Writeln('The amount in BDS is $',converted:2:2);
    end;

    5:BEGIN
    Writeln(' Please enter the amount to be converted from JMD to BDS:');
    readln( money);

    converted:=money*0.02;
    gotoxy(1,4);
    Writeln('The amount in BDS is $',converted:2:2);
    end;
    else
    begin
    Writeln;
    textcolor(yellow);
    Writeln(' Invalid choice!');
    end;
    end;
    Writeln(' Press any key to return to the main menu.');
    readkey;
    end;

    Procedure storereservation;

    VAR
    reservationinfo:reservations;
    returnday:integer;
    returnh:integer;
    totaldays:integer;
    discountcode:integer;
    discount:integer;
    choice:char;

    BEGIN

    clrscr;

    reset(reserve);

    Writeln;
    textcolor(yellow);
    Writeln(' Please enter the customers information as prompted.');
    textcolor(white);
    Window(2,3,80,5);
    Writeln('First Name:');
    Readln( reservationinfo.firstname);
    clrscr;
    Writeln('Last Name:');
    Readln( reservationinfo.lastname);
    clrscr;
    Writeln('Age:');
    Readln( reservationinfo.age);
    clrscr;
    Writeln('Date of Birth as DD MM YY');
    Readln( reservationinfo.dob);
    clrscr;
    Writeln('Country:');
    Readln( reservationinfo.country);
    clrscr;
    Writeln('City:');
    Readln( reservationinfo.city);
    clrscr;
    Writeln('Address:');
    Readln( reservationinfo.address);
    clrscr;
    Writeln('Telephone Number:');
    Readln( reservationinfo.phone);
    clrscr;
    Writeln('Email Address:');
    Readln( reservationinfo.email);
    clrscr;
    Writeln('Check IN Date as DD:');
    Readln( reservationinfo.checkinday);
    clrscr;
    Writeln('Check IN Month as MM:');
    Readln( reservationinfo.checkinmonth);
    clrscr;
    Writeln('Check OUT Date as DD:');
    Readln( reservationinfo.checkoutday);
    clrscr;
    Writeln('Check OUT Month as MM:');
    Readln( reservationinfo.checkoutmonth);
    clrscr;
    Writeln('Type of Room enter 1 for single, 2 for double or 3 for triple bed:');
    Readln( reservationinfo.typeofroom);
    clrscr;
    Writeln('Additional Comments:');
    Readln( reservationinfo.comments);
    clrscr;
    Writeln('Enter any valid discount code or just continue by typing 0:');
    Readln( discount);
    clrscr;

    CASE discountcode OF
    19029:
    begin
    discount:=20;
    end;
    20831:
    begin
    discount:=35;
    end;
    4909: begin
    discount:=50;
    end;
    else discount := 0;
    end;

    returnday := reservationinfo.checkinday;
    for count:=2 to reservationinfo.checkinmonth do
    begin
    if (count <= 12) Then
    begin
    returnday := returnday + dates[count-1];
    end;
    end;

    returnh := reservationinfo.checkoutday;
    for count:= 2 to reservationinfo.checkoutmonth do
    begin
    if (count <= 12) Then
    begin
    returnh := returnh + dates[count-1];
    end;
    end;

    totaldays:=returnh-returnday;

    case reservationinfo.typeofroom of
    1: begin
    reservationinfo.amountcharge:=(40*totaldays)-discount;
    end;

    2: begin
    reservationinfo.amountcharge:=(60*totaldays)-discount;
    end;
    else
    reservationinfo.amountcharge:=(80*totaldays)-discount;
    end;

    window(1,1,80,25);
    clrscr;
    Writeln;
    Writeln(' The amount to be paid is $',reservationinfo.amountcharge,'BDS');
    Writeln;

    Writeln(' Would you like to print a copy of the reservation information? y/n');
    readln(choice);

    if choice=y then
    begin
    Writeln(Lst,'Thank you for staying at the Sands Regency Hotel.');
    Writeln(Lst,'Below is you reservation information.');
    Writeln(Lst);
    Writeln(Lst,'-------------------------------------------------');
    Writeln(Lst);
    Writeln(Lst,'First Name: ',reservationinfo.firstname);
    Writeln(Lst);
    Writeln(Lst,'Last Name: ',reservationinfo.lastname);
    Writeln(Lst);
    Writeln(Lst,'Age: ',reservationinfo.age);
    Writeln(Lst);
    Writeln(Lst,'Date Of Birth: ',reservationinfo.dob);
    Writeln(Lst);
    Writeln(Lst,'Country: ',reservationinfo.country);
    Writeln(Lst);
    Writeln(Lst,'City: ',reservationinfo.city);
    Writeln(Lst);
    Writeln(Lst,'Address: ',reservationinfo.address);
    Writeln(Lst);
    Writeln(Lst,'Phone Number: ',reservationinfo.phone);
    Writeln(Lst);
    Writeln(Lst,'Email Address: ',reservationinfo.email);
    Writeln(Lst);
    Writeln(Lst,'Check In Date: ',reservationinfo.checkinday);
    Writeln(Lst);
    Writeln(Lst,'Check In Month: ',reservationinfo.checkinmonth);
    Writeln(Lst);
    Writeln(Lst,'Check Out Date: ',reservationinfo.checkoutday);
    Writeln(Lst);
    Writeln(Lst,'Check Out Month: ',reservationinfo.checkoutmonth);
    Writeln(Lst);
    Writeln(Lst,'Type of Room: ',reservationinfo.typeofroom);
    Writeln(Lst);
    Writeln(Lst,'Additional Comments: ',reservationinfo.comments);
    Writeln(Lst);
    Writeln(Lst,'Amount to be paid: ',reservationinfo.amountcharge, 'BDS');
    Writeln(Lst);
    Writeln(Lst,'Come Again!');
    end;
    seek(reserve,filesize(reserve));
    write(reserve,reservationinfo);
    gotoxy(2,5);
    readln;
    END;

    Procedure findreservation;
    var find:string;
    success:boolean;
    reservation:reservations;
    BEGIN
    reset(reserve);
    success:=FALSE;
    clrscr;
    textcolor(yellow);
    Writeln;
    Writeln(' Please enter the name of the customer:');
    textcolor(white);
    gotoxy(2,3);
    readln(find);
    While not eof(reserve) DO
    BEGIN
    read(reserve,reservation);
    IF (find=reservation.firstname) then
    begin
    clrscr;
    success:=true;
    TextColor(Yellow);
    writeln;
    writeln(' Reservation Found');
    TextColor(White);
    Writeln;
    Writeln(' First Name: ',reservation.firstname);
    Writeln;
    Writeln(' Last Name: ',reservation.lastname);
    Writeln;
    Writeln(' Age: ',reservation.age);
    Writeln;
    Writeln(' Date Of Birth: ',reservation.dob);
    Writeln;
    Writeln(' Country: ',reservation.country);
    Writeln;
    Writeln(' City: ',reservation.city);
    Writeln;
    Writeln(' Address: ',reservation.address);
    Writeln;
    Writeln(' Phone Number: ',reservation.phone);
    Writeln;
    Writeln(' Email Address: ',reservation.email);
    Writeln;
    Writeln(' Check In Date: ',reservation.checkinday);
    Writeln;
    Writeln(' Check In Month: ',reservation.checkinmonth);
    Writeln;
    Writeln(' Check Out Date: ',reservation.checkoutday);
    Writeln;
    Writeln(' Check Out Month: ',reservation.checkoutmonth);
    Writeln;
    Writeln(' Type of Room: ',reservation.typeofroom);
    Writeln;
    Writeln(' Additional Comments: ',reservation.comments);
    Writeln;
    Writeln(' Amount to be paid: ',reservation.amountcharge, 'BDS');
    Writeln;
    TextColor(Yellow);
    Writeln(' Press any key to return to the main menu.');
    gotoxy(2,36);
    readkey;
    end;
    end;
    IF (success=false) then
    BEGIN
    textcolor(yellow);
    Writeln;
    writeln(' Record not found, press any key to return to the main menu.');
    gotoxy(2,5);
    readkey;
    end;
    end;

    Procedure schedule;
    VAR Month,Day,DayOfWeek,Year:word;
    name:string;
    reservation:reservations;

    Begin
    clrscr;
    GetDate(Year,Month,Day,DayOfWeek);
    TextColor(yellow);
    gotoxy(2,2);
    Writeln('The customers below have reservations for today:');
    reset(reserve);
    While not eof(reserve) DO
    BEGIN
    read(reserve,reservation);
    IF (Month=reservation.checkinmonth) and (Day=reservation.checkinday) then
    begin
    textcolor(white);
    Writeln;
    Writeln(' ',reservation.firstname, ' ',reservation.lastname);
    end;
    end;
    textcolor(yellow);
    Writeln;
    Writeln(' Press any key to return to the main menu.');
    gotoxy(2,10);
    readkey;
    end;

    Procedure sorry;
    Begin
    textcolor(yellow);
    gotoxy(3,32);
    Writeln('Please enter a valid choice.');
    gotoxy(3,33);
    delay(1230);
    end;

    Procedure menu;
    BEGIN
    reset(textfile);
    while not eof(textfile) do
    begin
    textcolor(yellow);
    readln(textfile,y);
    writeln(y);
    end;

    textcolor(white);
    GetTime(Hour, Minute, Second, Hundredths);
    GetDate(Year,Month,Day,Weekday);
    gotoxy(3,19);
    Writeln('Todays date is ',Month:2,'/',Day:2,'/',Year);
    gotoxy(3,20);
    Writeln('The current time is ',Hour:2,':',Minute:2,':',Second:2);
    gotoxy(3,22);
    Writeln('Choose an option.');
    gotoxy(3,23);
    Writeln('1--> Book a reservation');
    gotoxy(3,24);
    Writeln('2--> Modify a reservation');
    gotoxy(3,25);
    Writeln('3--> Cancel a reservation');
    gotoxy(3,26);
    Writeln('4--> Convert between currencies');
    gotoxy(3,27);
    Writeln('5--> Search for reservation');
    gotoxy(3,28);
    Writeln('6--> View list of reservations for today');
    gotoxy(3,29);
    Writeln('7--> Exit Program');
    gotoxy(3,31);
    Writeln('Enter your choice:');
    end;

    Begin
    openFile;
    repeat
    clrscr;
    TextMode(c80+font8x8);
    menu;
    gotoxy(3,32);
    readln(choice);
    case choice of
    1:Begin
    storereservation;
    end;
    4:BEGIN
    currency;
    end;
    5:BEGIN
    findreservation;
    end;
    6:Begin
    schedule;
    end;
    7:Begin
    halt;
    end;
    else
    begin
    sorry;
    end;
    end;
    until choice=7;
    close(textfile);
    close(reserve);
    end.
  • It will work with pure DOS only, ( assuming that you have a printer on the LPT port ), Windows doesn't let your program to communicate directly with the printer ( or any hardware ) your code is running on a virtual machine, to access the printer you'd have to call the respective win API. Try to make a Dos boot disk or CD, then run your program from it.
  • is there any possible way to get this to work without using dos?

  • One way would be to use Free Pascal and call the win API (through windows unit ) responsible for printing....but you'd have to rewrite your code. Another thing is that today's printers are not necessarily compatible nor follow a standard (like most of those old dot printers, each have their specific drivers), so let the OS take care of the printing not your code ( by communicating directly with the hardware ), will save time and headache and your code will run with every printer since you're telling the OS to print something not to the hardware directly.
  • ok.. i am not an expert at this i would appreciate it if can you please explain to me what i need to do and the code i need to change...

    thanks you guys have been alot of help.
  • The quick and dirty solution is to send all your output to a file and then use Word or Notepad to print the file. :-( Not very elegant, I know.


  • This works fine with my Lexmark laser printer (connected via LPT1 port) on Win XP and FPC 2.2.2:[code][blue]{Compiler: FPC 2.2.2 Download it from: freepascal.org}
    program printer_test;

    const printer_name='LPT1'; { <-- assuming that the printer is on port LPT1}

    var lst:text;
    i:byte;

    begin
    assign(lst,printer_name);
    {$I-}rewrite(lst);{$I+}
    if ioresult<>0 then begin
    writeln('Printing failed...');
    { }
    end else
    for i:=1 to 10 do
    writeln(lst,'Hello world ! Line: ',i);
    close(lst);
    end.[/code]Although it doesn't print automatically, it flashes the "Continue" button to be pressed in order to start the job.

    P.S. I tried with TP7 and works as well...without the printer unit...seems like windows redirects "LPT1" named text files to the printer instead of the disk...
  • You could use Delphi as well. Basically the windows version of Pascal.
    There is a Personal version you can try with full functionality.
  • this is an assignment i am doing... thanks for all the help i will try to implement the code into my program and see how it works.

    is there any way to edit records after they have been stored?

  • :
    : is there any way to edit records after they have been stored?
    :

    This thread: http://www.programmersheaven.com/mb/pasprog/384937/384937/dos-pascal-dat-service-request/?S=B20000#384937 has a nice database implementation where you can see how is done.
  • i don't seem to understand how to modify it even after looking at the example... can somebody please post the main code here please... thanks

    sorry but i am not that good at this .
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories