Looping example again!!!

Let me explain the previous looping problem again

I want to use 2 groupboxes my first groupbox will be called first loop and will contain 2 spinedit buttons , these spinedit buttons can only contain integer values ,my second groupbox will be called second loop and will also contain 2 spinedit buttons , these spinedit buttons can also only contain integer values.I will have two edit buttons , one will be called my initial string edit box and i will enter letters in it like 'A' and the other edit box will be called my final string and this is only for output.So in other words when i click my loop button i want both the loops to run and the i want it to first add my initial string value that i put in 'A' and add the results from the 2 loops in the final strin edit box as output.This is all very confusin but i think you all get the point.Please look at the code and make any suggestions thank you.

unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Spin;

type
TfrmLooping = class(TForm)
gpbFirstLoop: TGroupBox;
gpbSecondLoop: TGroupBox;
lblStart: TLabel;
lblEnd: TLabel;
lblStart2: TLabel;
lblEnd2: TLabel;
lblInitialString: TLabel;
edtStringInitial: TEdit;
lblFinalString: TLabel;
edtStringOutput: TEdit;
sedStartFirst: TSpinEdit;
sedEndFirst: TSpinEdit;
sedStartSecond: TSpinEdit;
sedEndSecond: TSpinEdit;
btnLoop: TButton;
procedure btnLoopClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
frmLooping: TfrmLooping;

implementation

{$R *.dfm}

procedure TfrmLooping.btnLoopClick(Sender: TObject);
var
sString : String;
jIndex : Integer;
iIndex : Integer;
begin

for iIndex := sedStartFirst.Value downto sedEndFirst.Value do
begin
for jIndex := sedStartSecond.Value downto sedEndSecond.Value do
begin
sString := sString + IntToStr(iIndex) + IntToStr(jIndex);
end;
end.

Comments

  • : Let me explain the previous looping problem again
    :
    : I want to use 2 groupboxes my first groupbox will be called first loop and will contain 2 spinedit buttons , these spinedit buttons can only contain integer values ,my second groupbox will be called second loop and will also contain 2 spinedit buttons , these spinedit buttons can also only contain integer values.I will have two edit buttons , one will be called my initial string edit box and i will enter letters in it like 'A' and the other edit box will be called my final string and this is only for output.So in other words when i click my loop button i want both the loops to run and the i want it to first add my initial string value that i put in 'A' and add the results from the 2 loops in the final strin edit box as output.This is all very confusin but i think you all get the point.Please look at the code and make any suggestions thank you.
    :
    : unit Unit2;
    :
    : interface
    :
    : uses
    : Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    : Dialogs, StdCtrls, Spin;
    :
    : type
    : TfrmLooping = class(TForm)
    : gpbFirstLoop: TGroupBox;
    : gpbSecondLoop: TGroupBox;
    : lblStart: TLabel;
    : lblEnd: TLabel;
    : lblStart2: TLabel;
    : lblEnd2: TLabel;
    : lblInitialString: TLabel;
    : edtStringInitial: TEdit;
    : lblFinalString: TLabel;
    : edtStringOutput: TEdit;
    : sedStartFirst: TSpinEdit;
    : sedEndFirst: TSpinEdit;
    : sedStartSecond: TSpinEdit;
    : sedEndSecond: TSpinEdit;
    : btnLoop: TButton;
    : procedure btnLoopClick(Sender: TObject);
    : private
    : { Private declarations }
    : public
    : { Public declarations }
    : end;
    :
    : var
    : frmLooping: TfrmLooping;
    :
    : implementation
    :
    : {$R *.dfm}
    :
    : procedure TfrmLooping.btnLoopClick(Sender: TObject);
    : var
    : sString : String;
    : jIndex : Integer;
    : iIndex : Integer;
    : begin
    :
    : for iIndex := sedStartFirst.Value downto sedEndFirst.Value do
    : begin
    : for jIndex := sedStartSecond.Value downto sedEndSecond.Value do
    : begin
    : sString := sString + IntToStr(iIndex) + IntToStr(jIndex);
    : end;
    [red]end;[/red]
    : end.
    :
    First you need to set the sString to the initial value:
    [code]
    sString := edtStringInitial.Text;
    [/code]
    Then come the two loops. In this case you have used two nested loops, which means that the jIndex loop will be execute more than once. If you want to have two seperate loops, the code should be:
    [code]
    for iIndex := sedStartFirst.Value downto sedEndFirst.Value do
    sString := sString + IntToStr(iIndex);
    for jIndex := sedStartSecond.Value downto sedEndSecond.Value do
    sString := sString + IntToStr(jIndex);
    [/code]
    Finally you need to present the data to the user, by assigning the sStrin to the output control:
    [code]
    edtStringOutput.Text := sString;
    [/code]
    This is all the code (in the order in which they need to appear) for the button click event.
    Note: there was also a missing end in your code above.
  • : : Let me explain the previous looping problem again
    : :
    : : I want to use 2 groupboxes my first groupbox will be called first loop and will contain 2 spinedit buttons , these spinedit buttons can only contain integer values ,my second groupbox will be called second loop and will also contain 2 spinedit buttons , these spinedit buttons can also only contain integer values.I will have two edit buttons , one will be called my initial string edit box and i will enter letters in it like 'A' and the other edit box will be called my final string and this is only for output.So in other words when i click my loop button i want both the loops to run and the i want it to first add my initial string value that i put in 'A' and add the results from the 2 loops in the final strin edit box as output.This is all very confusin but i think you all get the point.Please look at the code and make any suggestions thank you.
    : :
    : : unit Unit2;
    : :
    : : interface
    : :
    : : uses
    : : Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    : : Dialogs, StdCtrls, Spin;
    : :
    : : type
    : : TfrmLooping = class(TForm)
    : : gpbFirstLoop: TGroupBox;
    : : gpbSecondLoop: TGroupBox;
    : : lblStart: TLabel;
    : : lblEnd: TLabel;
    : : lblStart2: TLabel;
    : : lblEnd2: TLabel;
    : : lblInitialString: TLabel;
    : : edtStringInitial: TEdit;
    : : lblFinalString: TLabel;
    : : edtStringOutput: TEdit;
    : : sedStartFirst: TSpinEdit;
    : : sedEndFirst: TSpinEdit;
    : : sedStartSecond: TSpinEdit;
    : : sedEndSecond: TSpinEdit;
    : : btnLoop: TButton;
    : : procedure btnLoopClick(Sender: TObject);
    : : private
    : : { Private declarations }
    : : public
    : : { Public declarations }
    : : end;
    : :
    : : var
    : : frmLooping: TfrmLooping;
    : :
    : : implementation
    : :
    : : {$R *.dfm}
    : :
    : : procedure TfrmLooping.btnLoopClick(Sender: TObject);
    : : var
    : : sString : String;
    : : jIndex : Integer;
    : : iIndex : Integer;
    : : begin
    : :
    : : for iIndex := sedStartFirst.Value downto sedEndFirst.Value do
    : : begin
    : : for jIndex := sedStartSecond.Value downto sedEndSecond.Value do
    : : begin
    : : sString := sString + IntToStr(iIndex) + IntToStr(jIndex);
    : : end;
    : [red]end;[/red]
    : : end.
    : :
    : First you need to set the sString to the initial value:
    : [code]
    : sString := edtStringInitial.Text;
    : [/code]
    : Then come the two loops. In this case you have used two nested loops, which means that the jIndex loop will be execute more than once. If you want to have two seperate loops, the code should be:
    : [code]
    : for iIndex := sedStartFirst.Value downto sedEndFirst.Value do
    : sString := sString + IntToStr(iIndex);
    : for jIndex := sedStartSecond.Value downto sedEndSecond.Value do
    : sString := sString + IntToStr(jIndex);
    : [/code]
    : Finally you need to present the data to the user, by assigning the sStrin to the output control:
    : [code]
    : edtStringOutput.Text := sString;
    : [/code]
    : This is all the code (in the order in which they need to appear) for the button click event.
    : Note: there was also a missing end in your code above.
    HELP PLS
    Ok thanks this works a bit better so far but onlu problem is that my value in my output box after clicking my loop button should be A272829373839 if i use 2 as my start integer and 3 as my end integer in groupbox 1 and 7 as my start integer and 9 as my end integer in groupbox 2 , so there must still be a problem somewhere.
    :

  • : : : Let me explain the previous looping problem again
    : : :
    : : : I want to use 2 groupboxes my first groupbox will be called first loop and will contain 2 spinedit buttons , these spinedit buttons can only contain integer values ,my second groupbox will be called second loop and will also contain 2 spinedit buttons , these spinedit buttons can also only contain integer values.I will have two edit buttons , one will be called my initial string edit box and i will enter letters in it like 'A' and the other edit box will be called my final string and this is only for output.So in other words when i click my loop button i want both the loops to run and the i want it to first add my initial string value that i put in 'A' and add the results from the 2 loops in the final strin edit box as output.This is all very confusin but i think you all get the point.Please look at the code and make any suggestions thank you.
    : : :
    : : : unit Unit2;
    : : :
    : : : interface
    : : :
    : : : uses
    : : : Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    : : : Dialogs, StdCtrls, Spin;
    : : :
    : : : type
    : : : TfrmLooping = class(TForm)
    : : : gpbFirstLoop: TGroupBox;
    : : : gpbSecondLoop: TGroupBox;
    : : : lblStart: TLabel;
    : : : lblEnd: TLabel;
    : : : lblStart2: TLabel;
    : : : lblEnd2: TLabel;
    : : : lblInitialString: TLabel;
    : : : edtStringInitial: TEdit;
    : : : lblFinalString: TLabel;
    : : : edtStringOutput: TEdit;
    : : : sedStartFirst: TSpinEdit;
    : : : sedEndFirst: TSpinEdit;
    : : : sedStartSecond: TSpinEdit;
    : : : sedEndSecond: TSpinEdit;
    : : : btnLoop: TButton;
    : : : procedure btnLoopClick(Sender: TObject);
    : : : private
    : : : { Private declarations }
    : : : public
    : : : { Public declarations }
    : : : end;
    : : :
    : : : var
    : : : frmLooping: TfrmLooping;
    : : :
    : : : implementation
    : : :
    : : : {$R *.dfm}
    : : :
    : : : procedure TfrmLooping.btnLoopClick(Sender: TObject);
    : : : var
    : : : sString : String;
    : : : jIndex : Integer;
    : : : iIndex : Integer;
    : : : begin
    : : :
    : : : for iIndex := sedStartFirst.Value downto sedEndFirst.Value do
    : : : begin
    : : : for jIndex := sedStartSecond.Value downto sedEndSecond.Value do
    : : : begin
    : : : sString := sString + IntToStr(iIndex) + IntToStr(jIndex);
    : : : end;
    : : [red]end;[/red]
    : : : end.
    : : :
    : : First you need to set the sString to the initial value:
    : : [code]
    : : sString := edtStringInitial.Text;
    : : [/code]
    : : Then come the two loops. In this case you have used two nested loops, which means that the jIndex loop will be execute more than once. If you want to have two seperate loops, the code should be:
    : : [code]
    : : for iIndex := sedStartFirst.Value downto sedEndFirst.Value do
    : : sString := sString + IntToStr(iIndex);
    : : for jIndex := sedStartSecond.Value downto sedEndSecond.Value do
    : : sString := sString + IntToStr(jIndex);
    : : [/code]
    : : Finally you need to present the data to the user, by assigning the sStrin to the output control:
    : : [code]
    : : edtStringOutput.Text := sString;
    : : [/code]
    : : This is all the code (in the order in which they need to appear) for the button click event.
    : : Note: there was also a missing end in your code above.
    : HELP PLS
    : Ok thanks this works a bit better so far but onlu problem is that my value in my output box after clicking my loop button should be A272829373839 if i use 2 as my start integer and 3 as my end integer in groupbox 1 and 7 as my start integer and 9 as my end integer in groupbox 2 , so there must still be a problem somewhere.
    : :
    :
    The problem is the use of "downto" instead of "to". "Downto" is using exclusively for looping from a high number to a low number, while "to" loops from a low number to a high number.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion