Page 1 of 1

Different Results

Posted: Thu Sep 25, 2008 7:13 am
by bjb007
I have an array (sHits) of 12 elements.
e.g. 2,2,2,2,2,3,3,3,3,3,3,3

I have varOne = 5 and VarTwo = 2

I want to know if the array has 5
elements which contain 2.

This code

Code: Select all

   put 0 into bOn
   repeat with i = 1 to 12
      if sHits[i] = Var2 then
         add 1 to bOn
      end if
   end repeat
correctly counts 5 occurrences of 2.

Then I want to set the backgroundColor of
the fields containing 2 to red with this

Code: Select all

   if bOn = Var1 then
      repeat with k = 1 to 12
         if sHits[k] = Var2 then
            set the backgroundColor of field ("fldS" & k) to red
         end if
      end repeat
   else
       etc...
Problem is that all twelve fields have their
backgroundColor set to red when only the five
containing 2 should be.

Any help appreciated.

Posted: Thu Sep 25, 2008 8:53 am
by Mark
Hi Bbj,

It looks like sHits = Var2 the moment you enter the repeat loop. Note that your repeat loop doesn't change the values of i and Var2, so this is either true or false for all fields.

You shouldn't check the value sHits to see whether a field contains 2! Somewhere in your script, you need a line:

Code: Select all

if field k is 2 then
Best,

Mark

Posted: Thu Sep 25, 2008 11:13 am
by SparkOut
or that if you do actually need to check the array for the match rather than check each field number then you need to be testing for sHits[k] in this loop, not - or change it to repeat with i = 1 to 12, not k.

Different Results

Posted: Fri Sep 26, 2008 1:30 am
by bjb007
There was a typo in the code.

When I changed the code to check the value
in the field I corrected it so that worked but didn't
try the corrected code using the array value.

Thanks for the help.