Why Im getting endless loop here?
let Srch := 'Search';
let Find := false;
let Counter := 1;
while Find = false do
let Slct := (select Company where Id = Counter).Employees;
if Slct = Srch then
'WD TXT' := "Found it";
Find = true
else
Counter = Counter + 1
end
end
1 reply
-
Hi rene
If Slct = Srch doesn't have true answer before Counter becomes larger than the largest Id in Company then Counter will continue to increment for ever and ever. You can check the maximum Id value and stop after Counter has reached this value
let Srch := 'Search';
let Find := false;
let Counter := 1;let MaxId := last((select Company order by Id).Id);
while Find = false and Counter <= MaxId do
let Slct := (select Company where Id = Counter).Employees;
if Slct = Srch then
'WD TXT' := "Found it";
Find = true
else
Counter = Counter + 1
end
endThere is a better type of loop, called a for loop, which means you don't need to keep track of a counter, so you can modify your code to
let Srch := 'Search';
let Find := false;
let Counter := 1;let MaxId := last((select Company order by Id).Id);
for Counter from 1 to MaxId +1 do
let Slct := (select Company where Id = Counter).Employees;
if Slct = Srch then
'WD TXT' := "Found it";Counter := MaxId
end
endEven better would be to dispense with the loop and modify the select statement
let Srch := 'Search';
let Counter := count(select Company where Employees = Srch);
if Counter > 0 then
'WD TXT' := "Found it"end
And now onto the second problem. You code isn't finding anything. I suspect that Employees is a link to an Employees table. The .Employees part of your select statement will just give a list of Ids. If you change this to .Employees.Name (or whatever you name field is called) you will have a list of names. Concatenate this and use the contains function to see if the name you are searching for is in the list.
let Srch := 'Search';
let Counter := count(select Company where contains(concat(Employees.Name),Srch));
if Counter > 0 then
'WD TXT' := "Found it"end
Regards John
Content aside
- 3 yrs agoLast active
- 1Replies
- 215Views