Recent

Author Topic: pascal :GotoXY problem  (Read 9211 times)

7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
pascal :GotoXY problem
« on: September 29, 2016, 03:55:58 pm »
users Crt;
var num,count2:integer;
{232,1}begin                     
num:=0;
count2:=0;
        while num=0 do
        begin
                repeat
                writeln('Press Enter to continue/Press ESC to exit');
                ch:=ReadKey;
                ClrScr;
                until (ch=#27) or (ch=#13);
                case ch of
                #13:begin
                        if (num=0) and (count2=0)
                        then begin
                               writeln('keep');
                               readln;
                               GotoXY(232,1);
                               end;
                               ClrScr;
                               delay(10000);
                               end;
                #27:exit;
                end;
        end;
end.



here is my code and i suppose GotoXY(232,1) get back to the beginning of the program but it doesn't work .Did i miss sth important or make it wrong?
7vinbaby

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11455
  • FPC developer.
Re: pascal :GotoXY problem
« Reply #1 on: September 29, 2016, 04:00:57 pm »
gotoxy puts the cursor at the position specified by the parameter (x,y) . It is not a flow control statement.

7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
Re: pascal :GotoXY problem
« Reply #2 on: September 29, 2016, 04:01:37 pm »
gotoxy puts the cursor at the position specified by the parameter (x,y) . It is not a flow control statement.

so if i want to go back to the beginning.What should i do??
7vinbaby

Fungus

  • Sr. Member
  • ****
  • Posts: 353
Re: pascal :GotoXY problem
« Reply #3 on: September 29, 2016, 04:07:26 pm »
You need to declare a label, position it and use goto:

Code: Pascal  [Select][+][-]
  1. program gotoxy;
  2. label label1; //declare the presence of the label
  3. uses ...;
  4. begin
  5. label1: //Declare the labels position
  6. ...
  7. goto label1; //Go to the labels position
  8. end;

Btw: Labels are a relic and you should not use them, other methods are better :-)

7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
Re: pascal :GotoXY problem
« Reply #4 on: September 29, 2016, 04:21:48 pm »
You need to declare a label, position it and use goto:

Code: Pascal  [Select][+][-]
  1. program gotoxy;
  2. label label1; //declare the presence of the label
  3. uses ...;
  4. begin
  5. label1: //Declare the labels position
  6. ...
  7. goto label1; //Go to the labels position
  8. end;

Btw: Labels are a relic and you should not use them, other methods are better :-)


So....what is the other methods? For example what?
7vinbaby

Fungus

  • Sr. Member
  • ****
  • Posts: 353
Re: pascal :GotoXY problem
« Reply #5 on: September 29, 2016, 04:52:18 pm »
You could use any type of loop, "while" or "repeat" would be my best suggestions.

Code: Pascal  [Select][+][-]
  1. program loopit;
  2. uses ...;
  3. var finish: boolean;
  4. begin
  5.   finish:= false;
  6.   repeat
  7.     if this then that
  8.     else finish:= true;
  9.   until finish;
  10.   //cleanup
  11. end;

Handoko

  • Hero Member
  • *****
  • Posts: 5158
  • My goal: build my own game engine using Lazarus
Re: pascal :GotoXY problem
« Reply #6 on: September 29, 2016, 05:19:36 pm »
So....what is the other methods? For example what?

While .. Do
http://wiki.lazarus.freepascal.org/WHILE..DO

Repeat .. Until
http://wiki.lazarus.freepascal.org/Until

For .. Do
http://wiki.lazarus.freepascal.org/FOR..DO

You may ask, which one should you use. Well, basically they're same just a bit different. For beginners, just pick the one you feel convenient.

Learning programming is fun. But learning randomly without step-by-step approach will slow your learning progress. I would recommend you these good tutorials:
http://www.pascal-programming.info/index.php
http://www.marcocantu.com/epascal/English/default.htm
http://www.taoyue.com/tutorials/pascal/index.html

After you have some basic knowledge about Pascal programming, then try to pick any topic you like in this tutorial page:
http://wiki.freepascal.org/Lazarus_Documentation#Lazarus_and_Pascal_Tutorials

Have fun!
« Last Edit: September 29, 2016, 05:22:41 pm by Handoko »

jma_sp

  • Full Member
  • ***
  • Posts: 150
  • El conocimiento si ocupa lugar.
Re: pascal :GotoXY problem
« Reply #7 on: September 29, 2016, 06:26:10 pm »
program go_to_xy;     // Name of the program.
uses crt;             // uses clause, we need crt, there is more units....

var // Now we need variables.

x,y:byte;    // declare variables for coordinates.

begin
     // First X >>>>>>>> then Y down
   ClrScr;     // Clean Screen
   GotoXY (1,1);
   Write ('We are here (1,1)');
   Delay (1500);  // Wait some time.....
   Write ('     Next (10,14) .....');
   GotoXY (10,14);
   Delay (1500);
   Write ('We are here now (10,14)');
   Delay (1500);
   x:=2; y:=5;   // Now our coordinates are (2,5)
   GoToXY (x,y);
   Write ('Hello 7vinbaby it is easy');
   Delay (1500);
   GotoXY (25,3);
   Write ('Now we clean the screen');
   Delay (1500);
   ClrScr;
   GotoXY (15,10);
   Write ('+------------------+');
   GotoXY (15,11);
   Write ('¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦');

   X:=15; Y:=12;
   for Y:=1 to 4 do
      begin
         GotoXY (X,11+Y);
         Write ('¦¦¦              ¦¦¦');
      end;

   GotoXY (15,Y+12);

   Write ('¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦');

   GotoXY (15,Y+13);

   Write ('+------------------+');

   Delay (1500);

   TextColor (14);
   GotoXY (18,13);
   Write ('H'); delay (400); Write  ('e'); Delay (400);
   Write ('l'); delay (400); Write ('l'); Delay (400); Write ('o');
   Delay (400);
   TextBackGround (7); TextColor (12); Write ('7'); TextColor (4);
   Delay (400); Write ('v'); Delay (400); Write ('i'); Delay (400);
   Write ('n'); Delay (400); Write ('b'); Delay (400); Write ('a');
   Delay (400); Write ('b'); Delay (400); Write ('y'); Delay (1500);
   // TextBackGround and TextColor change colors
   // Best with procedures and functions...

end.

You have to know the screen mode for maxX and maxY and here you hace ASCII table also in IDE menu of freepascal --> tools.

http://stanislavs.org/helppc/ascii.gif

Other ways are writing directly in video memory character and atribute and using interruptions INT 10h



Devuan Beowulf 3.0( JWM/ROX/iDesk) - Puppy Linux,  Haiku OS,.ReactOS 0.4.xx  - FreeDos .

jma_sp

  • Full Member
  • ***
  • Posts: 150
  • El conocimiento si ocupa lugar.
Re: pascal :GotoXY problem
« Reply #8 on: September 30, 2016, 09:35:55 am »
As explained Fongus you can use GOTO but you should avoid it. Instead learn how to use procedure, is a best way.
Also you can put  the code into another external  reapeat....until but you have to clear ch in each clicle with other value != (ch=#27) or (ch=#13); to avoid direct exit.

Sorry for my english....
Devuan Beowulf 3.0( JWM/ROX/iDesk) - Puppy Linux,  Haiku OS,.ReactOS 0.4.xx  - FreeDos .

7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
Re: pascal :GotoXY problem
« Reply #9 on: September 30, 2016, 03:33:57 pm »
users Crt;
var num,count2:integer;
{232,1}begin                     
num:=0;
count2:=0;
        while num=0 do
        begin
                repeat
                writeln('Press Enter to continue/Press ESC to exit');
                ch:=ReadKey;
                ClrScr;
                until (ch=#27) or (ch=#13);
                case ch of
                #13:begin
                        example1;            {find num}
                        example2;            {find count2}
                        if (num=0) and (count2=0)
                        then begin
                               writeln('keep');
                               readln;
                               GotoXY(232,1);
                               end;
                               ClrScr;
                               delay(10000);
                               example3;
                               example4;
                               end;
                #27:exit;
                end;
        end;
end.


i am sory i do not ask my question correctly.
Actually i want to end the initial  'while' loop after i find num&count2=0 and goto the beginning of looping(not execute example3 & 4)
Also if not(num&count2)=0 ,continue to execute example3 & example4
 
So how can i do?
7vinbaby

 

TinyPortal © 2005-2018