D@VE's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
7 (0.01 per day)
Joined:
04-May 13
Profile Views:
243
Last Active:
User is offline May 05 2013 10:01 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   D@VE has not set their status

Posts I've Made

  1. In Topic: Searching a listbox and retrieving & rearranging a string.

    Posted 5 May 2013

    I also tried:
    If strLastNameToSearch.ToUpper Like strSearch.ToUpper Then
            blnSearch = True
            End If
            Do
            intCounter += 1
            Loop Until intCounter > lstNames.Items.Count
    
    

    and
     While strLastNameToSearch.ToUpper Like strSearch.ToUpper = False
                Do
                    intCounter += 1
                Loop Until intCounter > lstNames.Items.Count
            End While
            If strLastNameToSearch.ToUpper Like strSearch.ToUpper = True Then
                blnSearch = True
            End If
    
    

    the 2nd returned "True" if the name was first in the listbox, but ran (what I'm assuming was) an endless loop for any other name. and yes, I'm trying whatever I can think of...
  2. In Topic: Searching a listbox and retrieving & rearranging a string.

    Posted 5 May 2013

    Where should I increment? And I'm really sorry! I keep messing up when I try to type the code in, so I'm going to try just copying and pasting exactly what I have. The lines of asterisks with "Works!" in them are parts of code that are working as intended. The line of asterisks with "WIP 1" in it, is where I tried to implement Modi123_1's solution. I tried to commet as much as I could...
        ' This function receives a string variable, which contains a last name to be used to search the listbox (which is in "Last, First" format).  It returns a boolean value of 
        ' true if the last name is found in the listbox, a value of false if it is not found.  This value is returned.
        Public Function SearchResults(ByVal blnSearch As Boolean) As Boolean
    
            '***************** Works! ********************************
            ' Declares  varaiable
            Dim intCounter As Integer = 0
    
            ' sets the initial selected index to o
            lstNames.SelectedIndex = intCounter
    
            ' Assigns the selected listbox item to a string variable
            strNameToSearch = lstNames.SelectedItem.ToString
    
            ' Indexes the comma in the name.
            intIndexOfComma = strNameToSearch.IndexOf(", ")
    
            ' separates the last name and assigns it to a string variable
            strLastNameToSearch = strNameToSearch.Substring(0, intIndexOfComma)
    
            '***************** WIP 1 ********************************
            ' For i As Int32 = 0 To lstNames.Items.Count - 1
            ' If lstNames.Items.ToString.ToUpper.Contains(strSearch.ToUpper) Then
            ' blnSearch = True
            ' end If
            'Next
    
            '***************** Works! ********************************
            ' compares it to the "search" string
            If strLastNameToSearch.ToUpper Like strSearch.ToUpper Then
                blnSearch = True
    
                '*******this is supposed to increment the index, but doesn't work************
            ElseIf blnSearch = False Then
                intCounter += 1
            End If
            '****************** Works! *******************************
            Return blnSearch
        End Function
    
    
  3. In Topic: Searching a listbox and retrieving & rearranging a string.

    Posted 5 May 2013

    Whoops, I left out some code... should look like this:
    [code]
    Public Function SearchResults(ByVal blnSearch As Boolean) As Boolean

    Dim intCounter As Integer = 0

    ' sets the initial selected index to o
    lstNames.SelectedIndex = intCounter

    ' converts the selected item to a string variable
    strNameToSearch = lstNames.SelectedItem.ToString

    ' separates the last name and assigns it to a string variable
    ' Indexes the comma in the name.
    intIndexOfComma = strNameToSearch.IndexOf(", ")
    strLastNameToSearch = strNameToSearch.Substring(0, intIndexOfComma)

    ' compares it to the "search" string
    If strLastNameToSearch.ToUpper Like strSearch.ToUpper Then
    blnSearch = True
    ' if it doesn't match, the index is incremented by one
    ElseIf intCounter += 1
    End If
    Return blnSearch
    End Function

    Ugh... forgot my closing code tag... sorry...
  4. In Topic: Searching a listbox and retrieving & rearranging a string.

    Posted 5 May 2013

    ok, as far as the 'console.writeline', no we have covered the last chapter that this class )Programming Fundamentals)covers and it hasn't been mentioned. I even checked the index to see if I missed it and it's not there... Sooo... anyway... i know I'm not supposed to put your exact code in, put I was wondering where, in my existing code, would I make the changes as referenced in your example. I rewrote your code to read as:
       Dim sSearchWord As String = "Doe"
        Dim foo As New List(Of String)
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            For i As Int32 = 0 To lstBox1.Items.Count - 1
                If lstBox1.Items(i).ToLower.Contains(sSearchWord.ToLower) Then
                    MessageBox.Show("Found it!")
                End If
            Next
        End Sub
    
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            lstBox1.Items.Add("john doe")
            lstBox1.Items.Add("jane doe")
            lstBox1.Items.Add("bobby droptables")
            lstBox1.Items.Add("frank theTank")
        End Sub
    End Class
    
    

    and it worked very nicely! Buuut, when I tried to use the same idea with my existing code, it did quite mesh. one of the problems is that I am only want a boolean value of "True" returned if the last name matches (If I'm not mistaken, your code looks at the entire contents of the listbox), so the listbox items have to be converted to strings, so I can separate the first and last names (that's why I whittle it down to:
    If strLastNameToSearch.ToUpper Like strSearch.ToUpper Then
    
    

    The code I'm used to using for incrementing the index of the selected listbox entry would look more like (I've added comments to explain what I'm trying to do with that particular chunk/line of code):
    Public Function SearchResults(ByVal blnSearch As Boolean) As Boolean
    
            Dim intCounter As Integer = 0
    
    ' sets the initial selected index to o
            lstNames.SelectedIndex = intCounter
    
    ' separates the last name and assigns it to a string variable
            strNameToSearch = lstNames.SelectedItem.ToString
    
    ' compares it to the "search" string
    If strLastNameToSearch.ToUpper Like strSearch.ToUpper Then
    
    
             blnSearch = True
    
    'this is supposed to increment the index, but doesn't work
             If blnSearch = False Then
            intCounter += 1
            End If
            End If
    
    
  5. In Topic: Searching a listbox and retrieving & rearranging a string.

    Posted 4 May 2013

    I'm guessing "foo" represents my listbox, but I we don't Dim listboxes, so I'm not sure. But, if it is, what is the proper code (in context to my existing code) for line 09? My list box is lstNames, so is that supposed to be:
    If lstNames.SelectedIndex(i).ToLower.Contains(sSearchWord.ToLower) Then 
    
    

    if so, how can you check "contains" on a numeric variable (the index) against a string (sSearch)? If it's supposed to be:
    If lstNames.SelectedItem(i).ToLower.Contains(sSearchWord.ToLower) Then 
    
    

    How can you identify the value(Item) with an integer (i)? I know I'm probably missing something completely, here... I can't press my lack of knowledge enough, I guess.

    Also, how would you use the "ToUpper" on an int32 (i)?

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

D@VE hasn't added any friends yet.

Comments

D@VE has no profile comments yet. Why not say hello?