Recent

Author Topic: Creating Procedure/Complete beginner  (Read 1027 times)

DontKnowName

  • Newbie
  • Posts: 2
Creating Procedure/Complete beginner
« on: June 04, 2021, 04:37:10 pm »
Hello,
In school we got a task an I cant solve it. We should draw 25 houses with a procedure which runs 25 times. I did everything to draw the houses, but cant put it into one procedure, im sitting here for 4 hours straight and would appreciate any help. I hope you can see the file below, its kinda hard for me to explain the problem.
Greetings,
Piet


Edit : Thank you for your helpful replies, even though I was too dumb to put the right file in here. I tried to put the code into procedures but get one error code after another. I'll upload the right file now and would be thankful for every advice you have <3
« Last Edit: June 04, 2021, 07:56:58 pm by DontKnowName »

dseligo

  • Sr. Member
  • ****
  • Posts: 318
Re: Creating Procedure/Complete beginner
« Reply #1 on: June 04, 2021, 06:56:53 pm »
Lazarus projects consists of several files. The file you sent is main project source and it doesn't contain your code.
If you want to show your project go to menu Project and then Publish Project. There you can create zip archive with necessary files and post it here, so we can compile your project and try to help you.

mas steindorff

  • Sr. Member
  • ****
  • Posts: 456
Re: Creating Procedure/Complete beginner
« Reply #2 on: June 04, 2021, 07:04:28 pm »
the key to successful programing is breaking up your code into smaller functions.  when you call a procedure, it can and often does, call other procedures that may also call other procedures.
all you need to do is to move your working code out of the main and into a procedure.  then call that procedure 25 times. 
What you have not said is what is the difference between the 1st call and the 2nd ...
do you need to draw it in a different position on the screen or do a "print page" if drawing on paper? That difference is what you will want to add as a parameter to your new procedure so you can make these adjustments in your new main().
windows 7/10 - laz 2.0 / 1.2.6 general releases

Thaddy

  • Hero Member
  • *****
  • Posts: 10796
Re: Creating Procedure/Complete beginner
« Reply #3 on: June 04, 2021, 07:10:41 pm »
Code: Pascal  [Select][+][-]
  1. program testloop25;
  2. procedure testme;
  3. var c:integer;
  4. begin
  5.   for c := 0 to 24 do
  6.     writeln('house ',c); // or whatever
  7. end;
  8. begin
  9.   testme;
  10. end.

DontKnowName

  • Newbie
  • Posts: 2
Re: Creating Procedure/Complete beginner
« Reply #4 on: June 04, 2021, 07:42:33 pm »
Thank you guys, your replies were very helpful even though I was too dumb to put the right file in here. I tried to split it up in a few more procedures but cant even get one to work. Its always a different error code. I'll upload the right file now, it would be great if you have a few more advices <3

howardpc

  • Hero Member
  • *****
  • Posts: 3729
Re: Creating Procedure/Complete beginner
« Reply #5 on: June 04, 2021, 09:40:20 pm »
See the attached project for an example of how to go about this.

 

TinyPortal © 2005-2018