?
Solved

Compare with InStr Check if Array Item is in a String

Posted on 2005-04-14
2
Medium Priority
?
371 Views
Last Modified: 2008-01-09
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").Rows
              sCurrentLetter = LCase(Left(Convert.ToString(dr.Item("tbo_Category")), 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_Category")) & "</a><BR>"
              sLastLetter = LCase(Left(Convert.ToString(dr.Item("tbo_Category")), 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>&nbsp;&nbsp;")
                  '  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>&nbsp;")
              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>&nbsp;&nbsp;")

Any help would be most appreciated, it is driving me nuts
0
Comment
Question by:tclgb
2 Comments
 
LVL 28

Accepted Solution

by:
rafrancisco earned 2000 total points
ID: 13786469
I think the problem is with this line:

sCurrentLetter = LCase(Left(Convert.ToString(dr.Item("tbo_Category")), 1))

You are converting the letters to lowercase and your alphabet is all in uppercase.

Hope this helps.
0
 

Author Comment

by:tclgb
ID: 13788618
Cheers for quick response.

What a schoolboy error.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question