Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with getting some output

Status
Not open for further replies.

AJW

Programmer
Aug 14, 2001
3
ZA
Hi, I was wondering how to get the data out of this procedure without freezing so that I can display it on a memo of in a edit field. Also is it possible to make a edit field display some text and then a string variable at the same time?

Heres the procedure
procedure TForm1.SearchClick(Sender: TObject);
var
I,Position,number : Integer;
Astring,BString:string;
A:boolean;
begin
number := StrToInt(input.Text);
I:=0;
Position:=0;
number:=0;
For I:= 0 to MaxNumbers do
begin
Repeat
IF A=false Then Begin
Num := number;
Position := I;
end
Until A=true;
end;
BString:= INTTOSTR(Position);
IF A=true then
sortedmemo.lines.add(Bstring)
Else
sortedmemo.lines.add('Number not Found');
end;

This code will compile but it just causes the comp to freeze... Its supposed to look in the array for 'Number' and if it finds it display where it found it in the array and if it deosnt a not found message.
Thanx for your help
 

Repeat
IF A=false Then Begin
Num := number;
Position := I;
end
Until A=true;

Your program is not locking up, it's in an endless loop as A is always false!

Pierre
 
Hi, I have managed to fix the endless loop. Now What I would like to do is make the program display on the memo if it found and what cell of the array it was found in.
I have tried the following code but can't get anything out of it except for'Number Not Found'
procedure TForm1.SearchClick(Sender: TObject);
var
I,Position,number : Integer;
Astring,BString:string;
A:boolean;
begin
number := StrToInt(input.Text);
I:=0;
Position:=0;
number:=0;
A:=false;
For I:= 0 to MaxNumbers do
begin
IF Num=Number Then A:=True;
While A = True Do
Position:= I;
end;
BString:= INTTOSTR(Position);
IF A=true then
sortedmemo.lines.add(Bstring);
IF A=False Then
sortedmemo.lines.add('Number not Found');
end;
Thanx for any help
 
Where are the variables/ constants Num and MaxNumbers declared. For example, I can't see the purpose of

IF Num=Number Then A:=True;

since you declare Number = 0. If you're testing for 0 why not write

A := (Num = 0);

Maybe if you could restate the objective of the code, or provide pseudo code I could be of more help.

Pierre


Pierre


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top