Board index » delphi » TPW for windows prob(includes code)

TPW for windows prob(includes code)

Hiya everyone this is my first post to this board and should be the
first of many.  OK heres my program the problem is that wed and sun do
not work properly at all. But mon (lin is this prog) works fine.  If
checked all of the code and I can not see a problem the otherdays codes
are both the same as mon but won't work like mon :(

thanks for any help in advance...

program linikersBar;

uses wincrt,strings;

{-----------------------------------------------------------------------
-------------------}

procedure wedmen;
begin
     clrscr;
     writeln('                  ___________________________________');
     writeln('                 |                                   |');
     writeln('                 |___________________________________|');
     writeln('                 |_______(Monday Bar Main menu)______|');
     writeln('                 |__|                              |_|');
     writeln('                 |__| Please enter your choice...  |_|');
     writeln('                 |__|______________________________|_|');
     writeln('                 |___________________________________|');
     menus;
     checkinput('               Enter selection:');
     wedoption:=number;
end;

procedure newwed;
begin
     {$I-}
     assign(wedfile, 'c:\wed.two');
     reset(wedfile);
     if ioresult <> 0 then
     begin
          rewrite(wedfile);
          writeln('creating a new file');
          readkey;
     end
     {$I+}
end;

procedure findwedposition;
begin
count:=0;
wedrecord.title:='x';
while not eof(wedfile) and (wedrecord.title<>'') do
begin
     count:=count+1;
     seek(wedfile,count);
     read(wedfile,wedrecord);
end;
if (wedrecord.title='') and (count<>0) then
count:=count-1;
writeln(count);
readkey;
end;

procedure addwed;
begin
     newwed;
     clrscr;
     findwedposition;
     count2:=count2+1;
     wedrecord.wednumber:=count2;
     writeln('You have chosen to add a booking to wednesday night');
     writeln('Enter the surname of the person who is booking a table');
     readln(wedrecord.title);
     writeln('enter first name ');
     readln(wedrecord.sname);
     writeln('Enter the number of people for that table');
     readln(wedrecord.nopepe);
     seek(wedfile,count);
     write(wedfile,wedrecord);
     close(wedfile);
end;

procedure viewed;
begin
     clrscr;
     writeln('All bookings for Wednesday night');
     header;
     newwed;
     count2:=0;
     while not (eof(wedfile)) do
     begin
          count2:=count2+1;
          seek(wedfile,count2);
          read(wedfile,wedrecord);
          writeln(wedrecord.wednumber:6,wedrecord.title:20,wedrecord.-
          sname:15);
     end;
     close(wedfile);
     readkey;
end;

procedure weddel;
var weddeletetitle:string[15];
begin
     clrscr;
     writeln('All bookings for wednesday nite');
     header;
     newwed;
     count2:=0;
     while not (eof(wedfile)) do
     begin
          count2:=count2+1;
          seek(wedfile,count);
          read(wedfile,wedrecord);
          writeln(wedrecord.wednumber:6,wedrecord.title:20,wedrecord.-
          sname:15);
     end;
     close(wedfile);
     newwed;
     writeln;
     writeln('Enter surname of cancelation: ');
     readln(weddeletetitle);
     count2:=0;
     wedrecord.title:='x';
     while not (eof(wedfile)) and (weddeletetitle<>wedrecord.title) do
     begin
          count2:=count2+1;
          seek(wedfile,count2);
          read(wedfile,wedrecord);
     end;
     if weddeletetitle=wedrecord.title then
     begin
          wedrecord.title:='';
          wedrecord.sname:='';
          wedrecord.nopepe:=0;
          seek(wedfile,count2);
          write(wedfile,wedrecord);
     end;

     begin
          writeln('Record not found ');
          write (chr(7)); {sounds a beep!}
          readkey;
     end;
end;

{-----------------------------------------------------------------------
--------------}

Procedure Monday;
begin
repeat
       monmenu;
       case monoption of
       1:enterdetails;
       2:printout;
       3:deletearecord;
       end;
       until monoption=4;
       mainmenu;
end;

procedure sunday;
begin
repeat sunmen;
       case sunoption of
       1:addsun;
       2:viesun;
       3:sundel;
       end;
       until sunoption=4;
       mainmenu;
end;

procedure wedbook;
begin
repeat wedmen;
       case wedoption of
       1:addwed;
       2:viewed;
       3:weddel;
       end;
       until wedoption=4;
       mainmenu;
end;

begin
strcopy(windowtitle,'::Liniker''s Bar');

repeat
      mainmenu;
      case option of
      1:Monday;
      2:wedbook;
      3:Sunday;
      end;
      until option=4;
      donewincrt;
end.

Due to space limitations I have just pasted the code of one of the days
causing problems.  thanks again..

--
Posted via http://dbforums.com

 

Re:TPW for windows prob(includes code)


Quote

> Due to space limitations I have just pasted the code of one of the
days
> causing problems.  thanks again..

> --
> Posted via http://dbforums.com

Best put your entire code on a webpage somewhere and post the link here.

At a first glance I can not see what the problem is, since there is not
enough code for me to compile the program and also see the differences
with the other days.
But a few tips might help.

I approve the use of a menu structure, but. I think the code will be
more clear to you if you place the entire code for one menu screen in
one procedure each.

So you get a structure like   (in TP)

procedure mymenu;
begin
  repeat
     clrscr;
     writeln('A= do this');
     writeln('B= do that');
     writeln('ESC= exit');
     case upcase(readkey) of
        'A':dothis;
        'B':dothat;
        #27:exit;
        else write(#7);  {beep}
    until false;
end;

The procedures dothis and dothat take exactly the same form.

You should try to AVOID global variabeles. Chances are that you
accidently modify it's value in another procedure.
If you need a return variabele from a procedure, turn it into a function
instead, or use var in the headers.

good luck

--
Femme

Re:TPW for windows prob(includes code)


I have taken your advice any tips would be welcome I have uploading the
program here

http://www.henry95.pwp.blueyonder.co.uk/Working.zip

its case sensitive

thanks,

--
Posted via http://dbforums.com

Re:TPW for windows prob(includes code)


Thanks for your help I think I will  change all my menus to the way you
sudgested it does make more sence.

I found out what was wrong and it was because I was using a global
variable it was gettinging modified and causing it to write the data to
the file wrongly I have now fixed this. Thank you,

I was wondering if you could help me with some more things for my
program I have got a add delete and list functions all fully functional
and Im in the process of making it able to back up its files but I would
welcome any other ideas of features that I could impliment.

thans again

--
Posted via http://dbforums.com

Re:TPW for windows prob(includes code)


"GRoberts" <member21...@dbforums.com> schreef in bericht
news:2369441.1042153335@dbforums.com...

Quote

> Thanks for your help I think I will  change all my menus to the way
you
> sudgested it does make more sence.

> I found out what was wrong and it was because I was using a global
> variable it was gettinging modified and causing it to write the data
to
> the file wrongly I have now fixed this. Thank you,

> I was wondering if you could help me with some more things for my
> program I have got a add delete and list functions all fully
functional
> and Im in the process of making it able to back up its files but I
would
> welcome any other ideas of features that I could impliment.

Well perhaps a few little tips (without looking at your sources)
I think this is interesting for many readers here.
What I am doing when saving information

Reserve the first lines for identifying what kind of file it is:
e.g. the name of the program
what you are saving here
very important A VERSION NUMBER
which is known in your program
possibly a comment list of what the changes are.
e.g.
const versionnumber=103;
{100= first version}
{101= added number of seats}
{102= customer_has_payed changed from boolean into integer 0=no 1=yes
2=50% payed }

The version number can be used to identify how, in what following order,
and which params are saved. This means that you can implement backward
compatibility. So the newer program is automatically able to read older
file formats.
It sounds difficult, but it isn't. See below

second tip
Use the same procedure for saving and loading.
A boolean (savenotload) determines if it is saving or loading

var ff:text;
     savenotload:boolean;

Create a number of functions like

function saveloadinteger(i:longint):longint;
begin
    if savenotload then writeln(ff,i) else readln(ff,i);
    saveloadinteger:=i;
end;

function saveloadreal(r:extended):extended;
.....

function saveloadstring(s:string):string:
.....

procedure saveloadboolean(var b:boolean);
....

Best make these declarations in a separate unit

OK. now what you have to do is to make one procedure that will do the
saving and loading of the entire set of items.

Procedure saveloadentireset(filename:string);
var i,copyofversnr:integer;
begin
   if not savenotload then emptyallthelists;
   assign(ff,filename);
   {$I-}
    if savenotload then rewrite(ff) else reset(ff);
    saveloadstring('This is a myfile file');
    saveloadstring('versionnumber');
    copyofversnr:=saveloadinteger(versionnumber);

    numberofitemsinlist:=saveloadinteger(numberofitemsinlist);
    for i:=1 to NumberOfItemsInList do
    begin
        if not savenotload then createnewiteminlist;
        with item[i]^ do
        begin
             name:=saveloadstring(name);
             age:=saveloadinteger(age);
             .......
        end;
        discountpercentage=saveloadreal(discountpercentage);
        saveloadboolean(itsarainyday);
        ......
    end;
   {$I+}
    if ioresult<>0 then error......
end;

It is ideal that you don't have to worry about the following order that
you save your params in. If you want to change the saving format, you
only have to change one procedure instead of two;

Now for the backward compatibility
If you want to change the fileformat increase the versionnumber param to
103

Suppose you want to add a param X to the set of saved params add in the
saveloadentireset something like
........
if copyofversnr >= 103 then X:=saveloadinteger(X) else X:=defaultvalue;
......

or if a param is not longer needed add something like
....
if copyofversionnumber<103 then saveloadi(0);
....

If you read the old version file copyofversnr gets the previously saved
value and treats the file as such.
If you save the file again, the current versionnumber and the
corresponding params will be saved.

If you are doing object oriented programming, this method is ideal,
since it is as difficult as adding one saveload procedure to the object.

--
Femme

Re:TPW for windows prob(includes code)


Thanks again for that but I don't really understand what your
trying to say.
My program now backs up its files to a floppy if asked to which is good.
I just can't get a search procedure to work heres what ive got so far.
Its pure of the top of my head.

procedure search;
var surname:string[15];
count:integer;
begin
         clrscr;
         count:=0;
         openfile;
         while not eof(linfile)do
         begin
              count:=count+1;no
              seek(linfile,count);
              read(linfile,linrecord);
              if surname=linrecord.sname then
              begin
                   header;
                   writeln(linrecord.linnumber:6,linrecord.title:20,lin-
                   record.sname:15);
                   readkey;
              end;
         end;
end;

--
Posted via http://dbforums.com

Other Threads