[thelist] ASP For Each...Next problem

Jason Handby jasonh at corestar.co.uk
Tue Jul 22 13:47:45 CDT 2003


Wade wrote:
> The For Each construction is usually used with collections, like
> Request.Form.

You can legitimately use it with arrays though. It should work.


Looking at the first couple of lines of your code, Michael...

> For Each FormDate In ArrFormDate
> For Each CurrDate In ArrCurrentDates(0,FormDate)

...what you've written in the second line implies that ArrCurrentDates is an
array of arrays. In other words, that ArrCurrentDates is a 2d array, and
that the contents of position (0, FormDate) in that array is itself an
array. Now I've never used GetRows() before, but a quick look at the
documentation (e.g.
http://www.devguru.com/Technologies/ado/quickref/recordset_getrows.html )
suggests that it just returns a 2d array, where each array element is a
variant -- not an array, which is what it would need to be for your code to
work.

Why don't you put the loops the other way around? Then you can just step
through the recordset, something like this:


  strFormDate = Request.Form("Date")
  ArrFormDate = Split(strFormDate,",")
  blnIsSame = false

  do until RS.EOF
    For Each FormDate In ArrFormDate
      blnIsSame = (FormDate = RS.Fields("Date"))
      If blnIsSame Then
        Exit For
      End If
    Next
    RS.MoveNext
  loop


HTH



Jason



More information about the thelist mailing list