I'm trying to dynamically create variables if possible.
I have a list box containing check boxes. The user selects items from it and the selections are then added to a database. They can select any number of items from the list (1-7). I have iterated through the selected items and added them to an arraylist.
I now want to store each selected item in a different variable to be added to the database. The idea is to use just one insert statement which is expecting 7 entries. If the user only selects say 2 items, these are inserted as well as 5 empty strings.
Dim part1 As String = ""
Dim part2 As String = ""
Dim part3 As String = ""
Dim part4 As String = ""
Dim part5 As String = ""
Dim part6 As String = ""
Dim part7 As String = ""
'add selected items to an array
For i = 0 To listPart.CheckedItems.Count - 1
selected.Add(listPart.CheckedItems(i).Text)
Next
I'd like to do something like:
For j = 0 To selected.Count
part+j = selected(j)
Next
This way I should have variables holding empty strings if the user does not select all 7 items