Recent

Author Topic: need help with calender  (Read 49695 times)

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: need help with calender
« Reply #120 on: September 24, 2017, 11:31:51 am »
only one but isn't i supposed to increase by 1 if the i is smaller or equal to 10. why does it not increase?

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: need help with calender
« Reply #121 on: September 24, 2017, 11:35:48 am »
only one but isn't i supposed to increase by 1 if the i is smaller or equal to 10. why does it not increase?
Because you don't have a loop aroung that increase of 1.

I think you need to go back to basics.

Make a program that prints out the numbers 1 through 100 into a TMemo.

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: need help with calender
« Reply #122 on: September 24, 2017, 11:47:58 am »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   memo1.clear;
  4.   for i:= 1 to 100 do
  5.   memo1.lines.add(inttostr(i));
  6. end;                    

here

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: need help with calender
« Reply #123 on: September 24, 2017, 11:50:49 am »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   memo1.clear;
  4.   for i:= 1 to 100 do
  5.   memo1.lines.add(inttostr(i));
  6. end;                    

here
So why are you using a for-loop here and not when you want to write the rank-records to the file?

(PS. Also don't forget to do proper indentation. You do know what I mean with indentation, or don't you? It's moving that memo1 line to the right 2 spaces so it's visible that it belongs to the for-loop.)

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: need help with calender
« Reply #124 on: September 24, 2017, 11:54:40 am »
cuz it does not work if i do that? wait does it work?
and yes sorry

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: need help with calender
« Reply #125 on: September 24, 2017, 01:21:35 pm »
ohh it works

but why didn't it work when i did that on create?

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: need help with calender
« Reply #126 on: September 24, 2017, 01:31:58 pm »
but why didn't it work when i did that on create?
In FormCreate you had the for-loop inside a while-loop. That was just silly coding.

Try to write what you want in English first (your normal thoughts).
Then translate it to Pascal.
You'll see that you didn't write the "for-loop" inside that while loop.

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: need help with calender
« Reply #127 on: September 24, 2017, 01:42:02 pm »
wait what is while loop?

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: need help with calender
« Reply #128 on: September 24, 2017, 01:56:05 pm »
wait what is while loop?
http://wiki.freepascal.org/WHILE..DO

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

Maybe you need to do some simple programming techniques first.
Do you have some learning books?

A simple exercise:
Write the numbers 33, 66, 99 etc (steps of 33) all below 600 into a TMemo.
How would you do that?
« Last Edit: September 24, 2017, 01:59:14 pm by rvk »

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: need help with calender
« Reply #129 on: September 24, 2017, 02:04:50 pm »
nope i do not have learning books

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   memo1.clear;
  4.   i:=33;
  5.   while i<600 do
  6.   begin
  7.    memo1.lines.add(inttostr(i));
  8.    i:=i+33;
  9.   end;
  10. end;      

like this? can you give me more exercises it's actually so fun :D

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: need help with calender
« Reply #130 on: September 24, 2017, 02:28:13 pm »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: need help with calender
« Reply #131 on: September 24, 2017, 03:02:57 pm »
like this? can you give me more exercises it's actually so fun :D
Yep. That's it.

You can find a lot of exercises online with Google. Just search for pascal exercises.

For example:
First create an array of 100 random numbers and then print out the highest number.

If you want to find exercises and tutorials on Pascal you can search for pascal tutorial pdf. (Or any combination with Pascal and Pdf in the search.

A lot of online resources have Pascal examples where you see writeln in the code.
For instance:
Code: Pascal  [Select][+][-]
  1. program test;
  2. begin
  3.   writeln('Hello world');
  4. end.

You can use such code in Lazarus by choosing Project > New Project > Simple Program
But when you run it, it will quit without showing you the world :D
(you get a black screen real fast with Hello world and it closes immediately)

You need to pause the program at the end of the program just put a readln; before the end.

Like this (try it):
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. uses sysutils;
  3. var
  4.   i: integer;
  5. begin
  6.   i:=33;
  7.   while i<600 do
  8.   begin
  9.     writeln(inttostr(i));
  10.     i:=i+33;
  11.   end;
  12.   readln; // <--- add this in online examples so the screen doesn't close
  13. end.

Just beginning with some of these simple programming techniques you'll learn the basics and the more complex programs will follow.

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: need help with calender
« Reply #132 on: September 24, 2017, 03:29:13 pm »
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. uses sysutils;
  3. var
  4.   i:integer;
  5.   randomm: array [1..100] of integer;
  6.  
  7. begin
  8.   i:=1;
  9.   while i<=100 do
  10.   begin
  11.     randomm[i]:=random(500);
  12.     writeln(inttostr(randomm[i]));
  13.     i:=i+1;
  14.   end;
  15.   readln;
  16. end.  

hi i don't know what to do next

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: need help with calender
« Reply #133 on: September 24, 2017, 03:43:08 pm »
hi i don't know what to do next
One remark. You've successfully filled the randomm array. But you did it with a while/do loop. Because you know the exact number of iterations for the loop you could also do it with a for/do loop with less lines:
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. uses sysutils;
  3. var
  4.   i:integer;
  5.   randomm: array [1..100] of integer;
  6. begin
  7.   for i := 1 to 100 do
  8.   begin
  9.     randomm[i]:=random(500);
  10.     writeln(inttostr(randomm[i]));
  11.   end;
  12.   readln;
  13. end.

After that... I asked for the highest number in the randomm-array.
In that case you would loop through the array and see what the highest number is.
If you do this in your mind... you check the first number and remember that.
You check the second number and see if it's higher. Is it higher you remember that number
and so on.

Now you just need to program that :)

pseudo code:
Code: Text  [Select][+][-]
  1. remembered number is 0
  2. loop through all number
  3.    if that number > remembered number then
  4.       remember that number
  5. print out the remembered number

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: need help with calender
« Reply #134 on: September 24, 2017, 03:46:15 pm »
where do i print that number?

 

TinyPortal © 2005-2018