msyed1
asked on
Dim Variables in a Loop
Hello,
I have the need to go through a loop to fill a listbox that I am dynamically creating. I need to dim a new ListItem
each time as in (below): I have just given a small sample here, the actual listbox is quite long and I want to do this in a loop if possible, but I don't know how to generate the variable names liAddItem1, liAddItem2, liAddItem3 etc. etc. going through a for-next loop. Please show me how to do this in VB.Net.
Dim liAddItem1 As New ListItem
liAddItem1.Text = "Add Platform >>"
liAddItem1.Value = "001"
lbxAddEditDel.Items.Add(li AddItem1)
Dim liAddItem2 As New ListItem
liAddItem2.Text = "Edit Platform >>"
liAddItem2.Value = "002"
lbxAddEditDel.Items.Add(li AddItem2)
Dim liAddItem3 As New ListItem
liAddItem3.Text = "Delete Platform >>"
liAddItem3.Value = "003"
lbxAddEditDel.Items.Add(li AddItem3)
'
Thanks much. msyed1.
I have the need to go through a loop to fill a listbox that I am dynamically creating. I need to dim a new ListItem
each time as in (below): I have just given a small sample here, the actual listbox is quite long and I want to do this in a loop if possible, but I don't know how to generate the variable names liAddItem1, liAddItem2, liAddItem3 etc. etc. going through a for-next loop. Please show me how to do this in VB.Net.
Dim liAddItem1 As New ListItem
liAddItem1.Text = "Add Platform >>"
liAddItem1.Value = "001"
lbxAddEditDel.Items.Add(li
Dim liAddItem2 As New ListItem
liAddItem2.Text = "Edit Platform >>"
liAddItem2.Value = "002"
lbxAddEditDel.Items.Add(li
Dim liAddItem3 As New ListItem
liAddItem3.Text = "Delete Platform >>"
liAddItem3.Value = "003"
lbxAddEditDel.Items.Add(li
'
Thanks much. msyed1.
You can use the same variable liAddItem for all items. Once item is added to the Items collection, you can reuse this variable again. Knowing this, you can write loop incrementing the Value and reading Text from some array.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.