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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop returning boolean value

Status
Not open for further replies.

MTarkington

Programmer
Feb 14, 2001
73
US
Good afternoon,

I am having a problem with a FOR loop returning a True/False value instead of the value that I need.

the code:
for counter := 1 to 70 do
(
if field = array_variable[counter] then
(
"success";
exit for;
)

I would think that if the field finds a match in the array, it would display "success", however, it does not display anything of fields that I KNOW it matches and it also only displays 'True' for 1 field in particular.

Any ideas?

TIA,
Mark
 
In CR syntax, you would do the following, ending by calling the variable:

stringvar x;
stringvar array y;
numbervar i;

for i := 1 to 70 do(
if {table.field} = y then
x := "Success");
x

Without the ending x, the formula would just return true.

-LB
 
Your formula wouldn't work, for several reasons, such as not declaring variables, etc.

You don't need a loop here anyway, try (CR syntax):

whileprintingrecords;
stringvar array MyArray := ["hello" , "world"];
if "world" in MyArray then
"Success"
else
"nope"

Replace "world" with your {table.field}

-k
 
That works & makes sense, thanks.

Now, another question:

What reason would I have for the code only picking up 1 value of the table to do the comparison with? Let me elaborate:

local stringvar code := tablename.code;
local stringvar codedesc;
local stringvar array code_value := [data for array];
local stringvar array code_number := [data for array];

for x := 1 to 70 do
( if code := code_number[x] then
codedesc := codenumber[x];
exit for; );
codedesc;

My report looks like this:

Code Value
1234
2334
1234
9087 9087
3459

For this, Code is from the db & value is the formula where codedesc is being returned.

I'm trying to show that for data I KNOW is in the database, I'm not getting the corresponding value.

I don't know if this makes sense. It's kinda difficult to describe.

TIA,
Mark
 
local stringvar code := tablename.code;
local stringvar codedesc;
local stringvar array code_value := [data for array];
local stringvar array code_number := [data for array];

for x := 1 to 70 do
(
if code = code_number[x] then //remove the colon
codedesc := codenumber[x]
);
codedesc;

-LB
 
The colon in the IF statement above was a mistake, I don't actually have that in my code.

Thanks,
Mark
 
Hi,
Are there multiple values for {tablename.code} in EACH record?

Where you place the formula will determine its scope..in the report details, for instance, it will evaluate once per record..But each evaluation will start fresh..

You may need to use Shared Variables and place the formula in the footer ( either Report or Group, depending on your needs)





[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
No, each record only has 1 code/value.

When I started this, I thought it would be fairly simple, and now it has become a monster.

I have 1 field in the DB that needs to have a description attached to it. I have 2 arrays that are hard-coded. The first array is the code the second is the description. I want to compare the field from the table to the first array & display the description from the second array.

Maybe I'm making this too difficult, but I really think my logic is pretty good.

Thanks for any input,
Mark
 
Aaaaah, got it, the original question had nothing to do with what you needed, great...

-k
 
I apologize to have apparently bothered you, but I tried to start at the lowest level and work my way up.

I thought that one issue was connected to the other. I was incorrect.

I just hope noone else out here has to deal with multiple-iteration Cache database tables. Not alot of fun but quite painful, if that's what you're into....

Mark
 
Posting accurate technical information is key, not doing so generally results in wasting time.

Conbsider builidng out more normalized data soruces win Views or Stroed Procedures on the database itself to avoid this sort of expense in the client layers.

-k
 
In theory, that sounds like a good idea. Problem is that our software vendor has our DB locked down b/c they don't want us creating stored procs and/or views for ourselves. So, we are at their mercy, using history tables, tables with fields that have multiple iterations, and reports that can take up to an hour to run.

Mark

 
Link (not import) to them using MS Access and use Queries in Access. The eventual queries can be the data soruces for Crystal's reporting requirements.

This will allow for reusability and simplified maintenance and prove faster and more flexible than Crystal.

-k
 
That is something I will try in the future, however, I absolutely need a resolution to my current issue.

Thanks,
Mark
 
Try removing the "exit for" and use the formula as I showed in my last response. When I added the "exit for" back in, I lost all but one value.

-LB
 
I dropped the 'exit for' but still only get 1 value populated.

Mark
 
Hi,
OK, lets try this:
Code:
local stringvar codedesc;
local stringvar array code_value := [data for array];
local stringvar array code_number := [data for array];
local NumberVar x;
for x := 1 to Ubound(code_value) do
(   if {table.code} = code_number[x] then
      codedesc := code_value[x]
         );
codedesc;

[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
You state earlier "I have 1 field in the DB that needs to have a description attached to it".

Why are you now expecting more than one value to be returned?

I think you nedd to post basics as your descriptions keep changing:

Example data (show what you have)
Expected output (show what is to be returned based on the example data)

-k
 
Turkbear, sorry, it didn't work.

Ok, here goes:

I have a single table.
This table has 1 code field that I am displaying on a report.
Beside this code field, I want a formula field that will display the corresponding description/value of the code that is being displayed.
My formula looks like the above code.
I want to compare the code on the report to the codes in the first array, then I want to attach the corresponding value to the code.

As of right this minute, on each DL, I am getting a code from the DB. I can see the code. In the formula field, I want to see the description, however, I am only seeing the description for one value of the code from the database. Example:

Code: Value:
1234 (blank) - formula unpopulated
2345 (blank) - formula unpopulated
3456 Patient treatment - formula populated
5678 (blank) - formula unpopulated
3456 Patient treatment - formula populated

This is what I'm getting. I need those blanks above to be the corresponding value from the array that I hard-coded in the formula field.

Any suggestions?

Mark
 
Please copy your actual formula into the thread.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top