Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 HELP!!! I'm stumped

Author  Topic 

rmclaws2k
Starting Member

4 Posts

Posted - 2001-11-17 : 21:04:03
I am building a web app that generates a dynamic alphabet menu (A B C D E.....) and only makes the letter clickable if there is at least one entry in the database that begins with the corresponding letter. The problem I am having is this:

'--------------------------------------------------
' Create and open Database Connection
'--------------------------------------------------
Set cnn2 = Server.CreateObject("ADODB.Connection")
cnn2.Open Application("VirtualGallery_ConnectionString")
Set rst2 = cnn2.Execute(sql2)

Alphabet = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z")

Dim TitlesArray
Dim NewTitleString
Dim i
Dim iCount
Dim iCurrentRecord

'--------------------------------------------------
' Build a string with the first letter of each
' entry, allowing no duplicates
'--------------------------------------------------
iCount = rst2.RecordCount
iCurrentRecord = 0
Do Until iCurrentRecord > iCount
TitleString = rst2("Title")
NewLetter = Mid(TitleString,1,1)
If NewLetter <> LastLetter Then
LastLetter = NewLetter
NewTitleString = NewTitleString & "'" & NewLetter
If iCurrentRecord < iCount Then
NewTitleString = NewTitleString & "', "
End If
End If
rst2.MoveNext
iCurrentRecord = iCurrentRecord + 1
Loop

'--------------------------------------------------
' Check result and make into array
'--------------------------------------------------
Response.Write NewTitleString
TitlesArray = Split(NewTitleString, ",")

'--------------------------------------------------
' Loop through alphabet, making the letter a
' hyperlink if there is a match in the array
'--------------------------------------------------
Dim iLoop2
iLoop2 = LBound(TitlesArray)
Dim iLoop
For iLoop = LBound(Alphabet) to UBound(Alphabet)
If TitlesArray(iLoop2) <> Alphabet(iLoop) Then
MenuString = MenuString & "<font color='#FFCC00'><b>" & Alphabet(iLoop) & "</b></font> "
Else
MenuString = MenuString & "<a href='/gallery/preview.asp?Letter=" & Alphabet(iLoop) & "' style='text-decoration: none'><font color='#FFCC00'><b>" & Alphabet(iLoop) & "</b></font> "
End If
iLoop2 = iLoop2 + 1
Next

'--------------------------------------------------
' Write the menu to the client
'--------------------------------------------------
Response.Write MenuString


The problem it gives me a "Subscript out of range" error. Am I approaching the problem correctly? Is there a way to build a query that automatically leaves only the first letter, and all duplicates? Thanks.
-StumpedInPhoenix

   

- Advertisement -