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!

Looping and showing correct 1

Status
Not open for further replies.

morechocolate

Technical User
Apr 5, 2001
225
US
Rather than doing something like this:

Local NumberVar x;

if {vExtHoldingReports.RATING} = "GOV" then x := 1 else
if {vExtHoldingReports.RATING} = "AGY" then x := 2 else
if {vExtHoldingReports.RATING} = "AAA" then x := 3 else
if {vExtHoldingReports.RATING} = "AA+" then x := 4 else
if {vExtHoldingReports.RATING} = "AA" then x := 5 else
if {vExtHoldingReports.RATING} = "AA-" then x := 6 else
x := 0;

I tried doing something like this the following, but it returns the value of true on each record if I do not put the x and it returns the last x value if I include the last x. I need it to put the appropriate value in the details section. I will also have to use x in another formula. I suppose I need to make that a global variable.

WhileReadingRecords;

Local StringVar Array Ratings;
Local NumberVar cnt;
Local NumberVar x;

Ratings := ["A","A-","A+","A1","A-1","A-1-","A-1+","A2","A-2","A-2-","A-2+","A3","AA","AA-];

For cnt := 1 to UBound(Ratings) Do
(
x := cnt
);
x <-- without this I get True, with it I get the upper bound value for all records.

Thanks

Pam
 
You forgot to tell the loop what to look for. I think the formula below will get you what you want. For each loop it checks to see if that position in the array is the same as the {vExtHoldingReports.RATING} field. If it is it places the loop number into x, if it's not the same x remains the same. x starts with the value of 0 in case {vExtHoldingReports.RATING} is not in the array.


Local StringVar Array Ratings;
Local NumberVar cnt;
Local NumberVar x:=0;

Ratings := [&quot;A&quot;,&quot;A-&quot;,&quot;A+&quot;,&quot;A1&quot;,&quot;A-1&quot;,&quot;A-1-&quot;,&quot;A-1+&quot;,&quot;A2&quot;,&quot;A-2&quot;,&quot;A-2-&quot;,&quot;A-2+&quot;,&quot;A3&quot;,&quot;AA&quot;,&quot;AA-&quot;];
For cnt := 1 to UBound(Ratings) Do
(if Ratings[cnt]= {vExtHoldingReports.RATING} then
x := cnt else x:=x

);
x


If you find the postings here in the Tek-Tips Forum helpful, please don't forget to let us know by using the &quot; Click here &quot; option. It's painless and lets us know our help has been useful and appreciated.

Mike

 
Thanks Mike,

I actually realized that later, but I then put my if statement in the incorrect place.

You were very helpful.

Thank You

Pam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top