CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Apr 2014
    Posts
    2

    .Find Ignore case

    Code:
        Private Sub SortColour()
            Dim ObjectList As New List(Of String)
            For i As Integer = 1 To lstObjects.Items.Count - 1
                ObjectList.Add(lstObjects.Items(i).ToString)
            Next
    
            Dim L As Integer = rtbRoom.TextLength
            For Each word As String In ObjectList
                Dim lastindex = rtbRoom.Text.LastIndexOf(word)
                Dim index As Integer = 0
                While index < lastindex
                    rtbRoom.Find(word, index, L, RichTextBoxFinds.None)
                    rtbRoom.SelectionColor = Color.Lime
                    index = rtbRoom.Text.IndexOf(word, index) + 1
                End While
            Next
        End Sub
    HI, looking for some friendly advice.

    Can anyone please tell me how I can get the above code to be NOT case sensitive.

    I've tried all sorts but can't fathom it. Any help will be greatly appreciated.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: .Find Ignore case

    Convert one to Lowecase (or upper), and then do a compare.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Apr 2014
    Posts
    2

    Re: .Find Ignore case

    hi dglienna. Thanks for your reply.

    If you're saying what I think you are. Then I'm certain I've tried this already.

    At the moment, I have a workaround but I really don't like it. It's basically repeating the same code twice.

    UnEdited:
    Code:
         Private Sub SortColour()
            Dim ObjectList As New List(Of String)
            For i As Integer = 1 To lstObjects.Items.Count - 1
                ObjectList.Add(lstObjects.Items(i).ToString)
            Next
    
            Dim rb(4) As RichTextBox
            rb(1) = rtbAfterOpen
            rb(2) = rtbAfterTurn
            rb(3) = rtbExamine
            rb(4) = rtbOpenExamine
    
            For I = 1 To 4
                Dim L As Integer = rb(I).TextLength
                For Each word As String In ObjectList
                    Dim lastindex = rb(I).Text.LastIndexOf(word)
                    Dim index As Integer = 0
                    While index < lastindex
                        rb(I).Find(word, index, L, RichTextBoxFinds.None)
                        rb(I).SelectionColor = Color.Lime
                        index = rb(I).Text.IndexOf(word, index) + 1
                    End While
                Next
            Next
    
            For i As Integer = 1 To lstObjects.Items.Count - 1
                ObjectList.Add(lstObjects.Items(i).ToString.ToLower)
            Next
    
            For I = 1 To 4
                Dim L As Integer = rb(I).TextLength
                For Each word As String In ObjectList
                    Dim lastindex = rb(I).Text.LastIndexOf(word)
                    Dim index As Integer = 0
                    While index < lastindex
                        rb(I).Find(word.ToLower, index, L, RichTextBoxFinds.None)
                        rb(I).SelectionColor = Color.Lime
                        index = rb(I).Text.IndexOf(word, index) + 1
                    End While
                Next
            Next
        End Sub

    Edited for ease of reading
    Code:
         Private Sub SortColour()
         Dim ObjectList As New List(Of String)
            For i As Integer = 1 To lstObjects.Items.Count - 1
                ObjectList.Add(lstObjects.Items(i).ToString)
            Next
    
            Dim rb As RichTextBox = rtbTemp
    
            Dim L As Integer = rb.TextLength
            For Each word As String In ObjectList
                Dim lastindex = rb.Text.LastIndexOf(word)
                Dim index As Integer = 0
                While index < lastindex
                    rb.Find(word, index, L, RichTextBoxFinds.None)
                    rb.SelectionColor = Color.Lime
                    index = rb.Text.IndexOf(word, index) + 1
                End While
            Next
    
            'Repeat the above. Converting to lower. 
            For i As Integer = 1 To lstObjects.Items.Count - 1
                ObjectList.Add(lstObjects.Items(i).ToString.ToLower)
            Next
    
            For Each word As String In ObjectList
                Dim lastindex = rb.Text.LastIndexOf(word)
                Dim index As Integer = 0
                While index < lastindex
    
                    rb.Find(word.ToLower, index, L, RichTextBoxFinds.None)
                    rb.SelectionColor = Color.Lime
                    index = rb.Text.IndexOf(word, index) + 1
                End While
            Next
        End Sub
    I don't like "cheating" I think it's bad practice. So this is just a temporary fix until I can find the correct solution.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured