Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read ListBox and Loop

Status
Not open for further replies.

RudeYute

MIS
Apr 9, 2001
6
GB
Hi,

I am trying to make objects move pixel by pixel after rading the contents of a listbox.

Ie,

ListBox contains: Up, Normal & Down.

Making the listbox is no probs, its the following I'm having trouble with.
I want to make a command button read those items individually, and when there is an up, it moves up one pixel (and +1 to the next time it does it), and when normal just move "number of pixels its currently moving", down, it to decrease the number of pixels it's on, by 1.

The actual coding aspect of thats not the problem, its just the command button to actually read through the list I'm having trouble with. And getting it to stop at the end of the list. If it could scroll through the listbox as it does it then even better.

I've so far tried:
CommandButton.Click
While (lbList.Items.Item("up")) Do
PicBox.Left += 1 Loop Do Loop Until (lbList.Items.Contains("down")) End Sub


That didn't seem to work as expected, and tried a few other ways but couldnt get it going.

Anyone help me out please?

Thanks
 
Hello

Something along the following lines would be more suitable for list iteration;

Code:
For Each itm as ListItem In lblList.Items
    [green]'itm is the actual listItem and provides you with
     'all accessible properties/methods[/green]
Next
 
So you are saying do:

Code:
For Each "Up" ListItem In lbList
            picturebox.Left += 1
Next
For Each "Normal" ListItem In lbList
            picturebox.Left += 0
Next
For Each "Down" List Item In lbList
            picturebox.Left -= 1

I have triued just using the top bit and get a syntax error on "ListItem" and Error "Contsant cannot be the traget of an assignment" for the "itm".
 
Hello

Sorry, forgot that the listbox has a base object collection rather then a strongly typed one.

The following should do it;
Code:
 'to iterate through choose one of the following
        For I As Int32 = 0 To ListBox1.Items.Count - 1
            Select Case True
                Case ListBox1.Items(I).ToString.IndexOf("up") > -1
                Case ListBox1.Items(I).ToString.IndexOf("down") > -1
                Case Else
            End Select
        Next

        'or this one
        For Each itm As Object In ListBox1.Items
            Select Case True
                Case itm.ToString.IndexOf("up") > -1
                Case itm.ToString.IndexOf("down") > -1
                Case Else
            End Select
        Next

        'Entirely up to you which one you choose
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top