[thelist] More ASP/database (almost there)...

Beau Hartshorne beau at gohothouse.com
Wed Apr 18 17:33:21 CDT 2001


> There are a couple ways to tackle this; 1) you can brute force it, by
> looping through the recordset and keep track of the previous Category, and
> if it changes, do your magic to separate the display. This would get the job
> done in a single pass, but it's not in any way reusable elsewhere if you
> have to do it a couple times (on the page, on the site), so I lean towards
> 2) store the recordset in an intermediary storage that allows you to work
> with the data multiple times without going back to the recordset --a
> dictionary.

Here's the working (untidy) code that I came up with, based on Scott's
AlmostVBScript Pseudo Code for everyone who's interested:

Dim CategoryKey, SubCat, CatList, key

Dim objDictionary
Set objDictionary = CreateObject("Scripting.Dictionary")

Do while not objRSSectors.EOF
CategoryKey = objRSSectors.Fields("SectorName")
SubCat = objRSSectors.Fields("Sub_SectorName")
CatList = objDictionary(CategoryKey)
objDictionary.Item(CategoryKey) = CatList & SubCat & ",,"
     objRSSectors.MoveNext
Loop

For each key in objDictionary
     objDictionary.Item(key) = Left(objDictionary.Item(key),
         Len(objDictionary.Item(key)) - 2)
Next

For each key in objDictionary
Response.Write("<p>")
Response.Write("<b>" & key & "</b>")
Response.Write("<br>")
     Response.Write(REPLACE(objDictionary.Item(key),",,","<br>"))
Response.Write("</p>")
Next

set objDictionary = Nothing





More information about the thelist mailing list