Skip to main content
Participating Frequently
May 22, 2006
Question

ASP loop brain freexe

  • May 22, 2006
  • 1 reply
  • 221 views
Hi,
I've got a bit of brain freeze with the following:
looping through a tbl which holds an ID value and a secondary value for each unique ID.

I need to set a value (CELLCOLOR) to be true if the secondary value is the same as::

at the min lets say I have four IDs:

101 - 10
102 - 20
103 - 20
104 - 30

ok what I need to happen is with the cellcolor value is (show in brackets):

101 - 10 ()
102 - 20 (YELLOW)
103 - 20 (YELLOW)
104 - 30 ()

Because 102 and 103 have the same value BOTH of those need to be set to yellow.

However my code only works for one ...

first I set the secondary value

then I check if that is the same as the previous - if yes then ceLLcolor is set.. is not leave it blank.

The problem is.. although that would work for record 103,.. it wouldn't work for 102 as it's previous is different,.. but I need it not to see that..

I've tried working it out based on the checking agianst the nextrecord and the previous but my code became too complicated...

I know this is simple, but my brain's fallen asleep - any ideas anyone?

Cheers


This topic has been closed for replies.

1 reply

Inspiring
May 22, 2006
First, stream your recordset into an array with GetRows(). That's the only
way you can have true random access of the data without having horrid
performance. Then it's a simple matter of checking the values. Below, I've
decided that I called the array MyData and that I've stored the UBound of
the array in a variable called MAX_ROW. Obviously, you can call them
whatever you want. I also stored all my field indexes in variables so I
don't have to remember them (ex: I_ID = 0, I_Name=1, etc.)

<%
For X = 0 to MAX_ROW
CellColor = "white"
If X > 0 Then
If MyData(I_SecValue,X) = MyData(I_SecValue,X-1) Then
CellColor = "yellow"
End If
ElseIf X < MAX_ROW
If MyData(I_SecValue,X) = MyData(I_SecValue,X+1) Then
CellColor = "yellow"
End If
End If
%>
<tr>
<td><%=MyData(I_ID,X)%></td>
<td
style="background-color:<%=CellColor%>"><%=MyData(I_SecValue,X)%></td>
</tr>
<%
Next
%>

"jamesy" <mtm81@hotmail.com> wrote in message
news:e4s6ja$cs8$1@forums.macromedia.com...
> Hi,
> I've got a bit of brain freeze with the following:
> looping through a tbl which holds an ID value and a secondary value for
> each
> unique ID.
> I've tried working it out based on the checking agianst the nextrecord and
> the
> previous but my code became too complicated...