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

    Noob needs loop help - lstbox counter

    I am pretty new to this subject. I am learning alright as I have toyed with java along with html, css etc..

    I am trying to make a basic app that will loop through an unordered list with repeats and count how many times a specific item repeats. Example would be I select a state from the list box and it will tell me how many times it is listed.

    This is the code I have up so far, trying to keep it basic. I am missing something, something related to the counter? I think I have some of the better half up but I am not sure...


    Code:
     Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstBox.SelectedIndexChanged
    
            Dim wins As String = lstBox.SelectedIndex
            Dim foundwins As Boolean = False
            Dim i As Integer = -1
    
    
    
            Do Until (i = lstBox.Items.Count - 1)
                i += 1
                If CStr(lstBox.Items(i)).StartsWith(wins) Then
                    foundwins = True
                End If
            Loop
            If foundwins = True Then
                outBox.Text = CStr(lstBox.Items(i))
            End If
    
    
        End Sub
    End Class

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Noob needs loop help - lstbox counter

    This is a Visual C++ Forum, ... however your code looks like VB one...
    Last edited by VictorN; December 1st, 2014 at 05:46 AM.
    Victor Nijegorodov

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Noob needs loop help - lstbox counter

    As Victor said, wrong language, but I don't see you counting anything. Doesn't SelectIndex give you the currently selected index, and not the string?

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