I am trying to read strings from listbox column into an array so I can then write that data to a file. But I get an Out of bounds exception for ‘counter’ I believe it is and I don’t understand why.
For counter as integer = 0 to edittracksListbox1.ListCount - 1
SelectedRows(counter) = Me.Cell( counter, 0) // update edited tracks list to write to file when save button clicked
SelectedRows needs to be an array of strings. And it needs to have at least an upper bound of edittracksListbox1.ListCount - 1
Dim SelectedRows() As String
ReDim(edittracksListbox1.ListCount - 1)
For counter as integer = 0 to edittracksListbox1.ListCount - 1
SelectedRows(counter) = Me.Cell( counter, 0)
Next
Or you could do:
Dim SelectedRows() As String
For counter as integer = 0 to edittracksListbox1.ListCount - 1
SelectedRows.Append Me.Cell( counter, 0)
Next
Both will give you the same SelectedRows array.
This is such a confusing language. I have a listbox that gets populated at time window opens. Then I have an add button and a delete button. Click one of those buttons and the listbox is increaed by a value or decreased by a value. I have those working fine.
But when that happens I need to update the above mentioned array so it can be written and saved to a file. But when I try and use the above code in the action section for either button , I get Pushbutton has no ‘cell’ member exception. The following code works in the open of the listbox but that doesn’t allow me to update the selectedrows array. Where the hell do I put the code to update the array after listbox is added to or deleted from? I have another button that is a save button once user finished with updating the listbox values, but it won’t let me put this code in it’s action either.
For counter as integer = 0 to edittracksListbox1.ListCount - 1
SelectedRows(counter) = Me.Cell( counter, 0)
Next
Every object has its own set of methods and properties, i.e., things you can do with it and things it can store. The Listbox has a Cell method but the Pushbutton does not. However, you can send a message or command from one object (Pushbutton) to another (Listbox) just by referencing it by name.
So if you want to put the code into the Pushbutton.Action, and you want to access the Listbox.Cell, you would simple call SelectedRows(counter) = EditTracksListbox1.Cell(counter, 0).