tclgb
asked on
Compare with InStr Check if Array Item is in a String
I have an Array of the Alphabet
I have a dataset that I page through and add the first letter of each category to a string
called sActiveLetters Itry to write links out as Anchors but when I run code it is not returning true.
sActiveLetters is full eg. abcdefghijklmnoprstvw
My Code is Below
Dim sRetStr As String = ""
Dim sCurrentLetter As String = ""
Dim sLastLetter As String = ""
Dim sActiveFirstLetters As String = ""
Dim vAlphabet(26) As String
vAlphabet(1) = "A"
vAlphabet(2) = "B"
vAlphabet(3) = "C"
vAlphabet(4) = "D"
etc....
For Each dr In CatlistDS.Tables("Cats").R ows
sCurrentLetter = LCase(Left(Convert.ToStrin g(dr.Item( "tbo_Categ ory")), 1))
If sCurrentLetter <> sLastLetter Then
sActiveFirstLetters = sActiveFirstLetters & sCurrentLetter
sRetStr = sRetStr & "<a name=""" & sCurrentLetter & """></a>"
sRetStr = sRetStr & "<h2>" & sCurrentLetter & "</h2><hr>"
End If
sRetStr = sRetStr & "<a class=CatsList >" & Convert.ToString(dr.Item(" tbo_Catego ry")) & "</a><BR>"
sLastLetter = LCase(Left(Convert.ToStrin g(dr.Item( "tbo_Categ ory")), 1))
Next
'' now, you've got the categories in a variable called "sRetStr" -- let's write out the alphabet letter list for page anchors:
For i = 1 To 26
If InStr(sActiveFirstLetters, vAlphabet(i)) > 0 Then
' then it's valid, write a link!
Response.Write("<a class=Listing href=""#" & vAlphabet(i) & """>" & vAlphabet(i) & "</a> ")
' Else
'' didn't find the letter in my string of active letters, so I guess it's not active...
' Response.Write("<span class=inactiveListing>" & vAlphabet(i) & "</a> ")
End If
Next
It is the 3 lines below that are not executing as planned
If InStr(sActiveFirstLetters, vAlphabet(i)) > 0 Then
' then it's valid, write a link!
Response.Write("<a class=Listing href=""#" & vAlphabet(i) & """>" & vAlphabet(i) & "</a> ")
Any help would be most appreciated, it is driving me nuts
I have a dataset that I page through and add the first letter of each category to a string
called sActiveLetters Itry to write links out as Anchors but when I run code it is not returning true.
sActiveLetters is full eg. abcdefghijklmnoprstvw
My Code is Below
Dim sRetStr As String = ""
Dim sCurrentLetter As String = ""
Dim sLastLetter As String = ""
Dim sActiveFirstLetters As String = ""
Dim vAlphabet(26) As String
vAlphabet(1) = "A"
vAlphabet(2) = "B"
vAlphabet(3) = "C"
vAlphabet(4) = "D"
etc....
For Each dr In CatlistDS.Tables("Cats").R
sCurrentLetter = LCase(Left(Convert.ToStrin
If sCurrentLetter <> sLastLetter Then
sActiveFirstLetters = sActiveFirstLetters & sCurrentLetter
sRetStr = sRetStr & "<a name=""" & sCurrentLetter & """></a>"
sRetStr = sRetStr & "<h2>" & sCurrentLetter & "</h2><hr>"
End If
sRetStr = sRetStr & "<a class=CatsList >" & Convert.ToString(dr.Item("
sLastLetter = LCase(Left(Convert.ToStrin
Next
'' now, you've got the categories in a variable called "sRetStr" -- let's write out the alphabet letter list for page anchors:
For i = 1 To 26
If InStr(sActiveFirstLetters,
' then it's valid, write a link!
Response.Write("<a class=Listing href=""#" & vAlphabet(i) & """>" & vAlphabet(i) & "</a> ")
' Else
'' didn't find the letter in my string of active letters, so I guess it's not active...
' Response.Write("<span class=inactiveListing>" & vAlphabet(i) & "</a> ")
End If
Next
It is the 3 lines below that are not executing as planned
If InStr(sActiveFirstLetters,
' then it's valid, write a link!
Response.Write("<a class=Listing href=""#" & vAlphabet(i) & """>" & vAlphabet(i) & "</a> ")
Any help would be most appreciated, it is driving me nuts
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What a schoolboy error.