Link to home
Start Free TrialLog in
Avatar of msyed1
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(liAddItem1)

                    Dim liAddItem2 As New ListItem
                    liAddItem2.Text = "Edit Platform >>"
                    liAddItem2.Value = "002"
                    lbxAddEditDel.Items.Add(liAddItem2)

                    Dim liAddItem3 As New ListItem
                    liAddItem3.Text = "Delete Platform >>"
                    liAddItem3.Value = "003"
                    lbxAddEditDel.Items.Add(liAddItem3)
                    '
                   
Thanks much. msyed1.
Avatar of AlexFM
AlexFM

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
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial