Recent

Author Topic: Output to a Memo or textbox [Solved]  (Read 4649 times)

Ramijami

  • Jr. Member
  • **
  • Posts: 87
Output to a Memo or textbox [Solved]
« on: August 23, 2011, 11:03:14 am »
Hi Everybody,

I am new to Lazarus programming, but am familiar with BASIC. Using one of my programmes written in BASIC to help learn Lazarus and need some help please. The programme I am working on is a Lottery programme that prints ALL combinations as per the code below:

Code: [Select]
var

a,b,c,d,e,f,n,count: integer;

begin
 n:= 7;
 count:= 0;
FOR a:= 1 TO n - 5 DO
FOR b:= a + 1 TO n - 4 DO
FOR c:= b + 1 TO n - 3 DO
FOR d:= c + 1 TO n - 2 DO
FOR e:= d + 1 TO n - 1 DO
FOR f:= e + 1 TO n DO


begin
  count:= count+1;
  //writeln(a,',',b,',',c,',',d,',',e,',',f);

end;    {ends for loop}
         writeln(count,' Lines Generated');

writeln;

writeln;

writeln('Press <Enter> To Quit');

readln();
end.

This works fine in the console window, but I need some help outputing the results to textbox or memo (or Listbox?) in a GUI. After trying on my own for a few days and doing a search in the forum for ideas I am only able to print the variable name (e.g. it will only print "a" or "f" but it doesn't print the six numbers in sequence. I'm sure it's a simple solution but I am stumped and any help would be much appreciated.

Thanks
« Last Edit: October 19, 2012, 10:56:11 am by Ramijami »

Bart

  • Hero Member
  • *****
  • Posts: 5713
    • Bart en Mariska's Webstek
Re: Output to a Memo or textbox
« Reply #1 on: August 23, 2011, 11:58:14 am »
Something like this?

Code: [Select]
  ...
  Memo1.Lines.Add(IntToStr(a) + ' ' + IntToStr(b) + ' ' + IntToStr(c) + ' ' + IntToStr(d) + ' ' + IntToStr(e) + ' ' + IntToStr(f));
  ...

or using the format() function

Code: [Select]
  ...
  Memo1.Lines.Add(Format('%d %d %d %d %d %d',[a,b,c,d,e,f]));
  ...

Using Format() has the advantage that you can specify the minimum width of the output for each integer, see the documentation.

Bart

Ramijami

  • Jr. Member
  • **
  • Posts: 87
Re: Output to a Memo or textbox
« Reply #2 on: August 23, 2011, 01:29:49 pm »
Thanks for the quick response Bart, this is exactly what I was looking for.

 

TinyPortal © 2005-2018