im trying to draw a box using gotoxy and fucntions.

this is what i have at the moment, but dont know what to do next to complete it:

Program box;

uses Crt;

procedure draw(x1,y1,x2,y2:integer);
begin
 gotoxy(x1,y1);
 write('.');
 gotoxy(x2,y2);
 write('.');
 gotoxy(x1,y2);
 write('.');
 gotoxy(x2,y1);
 write('.');
end;

begin
 draw(10,10,15,15);
end.

you need cycles anyway
if you want to put symbols onto each position between y1 and y2, do like this:

for y:=y1 to y2 do begin
  gotoxy(x,y);
  write('.');
end;

of course, you should check, whether y1 is less than y2
do the same 4 times:
x1->x2, y=y1
x1->x2, y=y2
y1->y2, x=x1
y1->y2, x=x2

we need the ascii code table to create this application... :D

Program box;

uses Crt;
(*your procedure same as the procedure window in the crt unit...*)


procedure draw(x1,y1,x2,y2:integer);

   (*local procedure line1*)
   procedure line1(a,b,c,e:integer);
   (*writes a - line to the screen*)
   (*a and b are the starting position*)
      begin
      gotoxy(a,b);
      while c <= e do begin
         inc(c,1);
         write(#196);
      end;
   end;(*end of line1*)

   (*local procedure line2*)
   (*this writes a | line to the screen*)
   procedure line2(a,b,c,e:integer);
   begin
        while c <= e do begin
            gotoxy(a,b);
            write(#179);
            inc(c,1);
            inc(b);
        end;
   end;(*end of line2*)


begin
   gotoxy(x1,y1);(*upper left corner of the box*)
   write(#218);
   gotoxy(x2,y1);(*upper right corner of the box*)
   write(#191);
   (*let's go back to the upper left corner*)
   (*and concatenate the upper corners...*)
   line1(x1+1,y1,x1,x2-2);

   gotoxy(x2,y2);(*lower right corner of the box*)
   write(#217);
   gotoxy(x1,y2);(*lower left corner of the box*)
   write(#192);
   line1(x1+1,y2,x1,x2-2);(*concat the lower corners*)

   line2(x1,y1+1,y1,y2-2);(*concat the left sides of the box*)
   line2(x2,y1+1,y1,y2-2);(*and last,concat the right sides too*)

end;

begin
 clrscr;
 draw(5,1,20,20);
 readln;
end.
(*by FlamingClaw 2010*)

Now ,you can modify your draw procedure's parameters as you like.

This article has been dead for over six months. Start a new discussion instead.