Hello, I need to know how to "extract" information out of list box.

Dim intLoop As Integer
        Dim blnStartG As Boolean
        Dim intCounter As Integer
        Dim strMedal As String

        Dim intcheck As Integer

        For intLoop = 0 To (lstResults.Items.Count = -1)
            blnStartG = False
            strMedal = lstResults.?????????
            blnStartG = strMedal.StartsWith("G")
            If blnStartG = True Then
                intCounter = intCounter + 1
            End If
            intcheck = intcheck + 1
        Next
        MessageBox.Show("Total amount of gold medals are: " & intCounter & " " & intcheck, "Amount", MessageBoxButtons.OK, MessageBoxIcon.Information)

What I am trying to do is count all the items that start with "G". I'm sure the method I'm trying to use is correct but I need to know how to get the name of the item from the List box to the varible "StrMedal".

Many thanks, Anthony

P.s I know know its a strange program, its for college ;)

Recommended Answers

All 3 Replies

Can you use a For Each statement with a list?

Dim word as String
For Each word in lstResults
strMedal = word
blnStartG = strMedal.StartsWith("G")

etc . . .

The for statement won't work coz I won't know how many items will be in the list box.

What I need to know is what code do I need to pull out the name of the item in the list box.

So if I had in a list box..

Gold - Running
Silver - Swimming
Gold - 100 meter

it would pull out all the names from the list box that starts with "G" and processes the name. Sorry if it isn't very clear

I'm not talking For statements - I'm talking For Each and Next . . .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.