-
I need to remove an item from a list box. The items added to the list box are stored in a two dimentional array! How can I remove an item from the array as well as the listbox without leaving the position in the list index blank?
Any ideas would be very helpful!
Thanks
Jamie
Here's my code:
Option Explicit
Dim hold()
Dim cPrice As Currency
Dim x As Integer
Dim Kelley As String
Dim ItemPrice
Dim listAr()
Dim y As Integer
Dim b As Integer
Dim z As Integer
Dim sTotal
Dim itemTotal
Dim itemSubtotal
Dim abc
Dim xyz
Dim pr
Dim p
Dim subtotal
Dim j
Private Sub Form_Load()
ReDim listAr(6, 3)
ReDim hold(6, 1)
j = "$"
hold(0, 0) = "Pepper Jelly "
hold(0, 1) = "15.99"
hold(1, 0) = "Grape Jelly "
hold(1, 1) = 3.99
hold(2, 0) = "Grape Jam "
hold(2, 1) = 3.99
hold(3, 0) = "Peach Preserves "
hold(3, 1) = 4.99
hold(4, 0) = "Pear Jelly "
hold(4, 1) = 3.99
hold(5, 0) = "Pear Preserves "
hold(5, 1) = "10.99"
hold(6, 0) = "Crabapple Jelly "
hold(6, 1) = 4.99
cboProduct.AddItem hold(0, 0) & j & hold(0, 1)
cboProduct.AddItem hold(1, 0) & j & hold(1, 1)
cboProduct.AddItem hold(2, 0) & j & hold(2, 1)
cboProduct.AddItem hold(3, 0) & j & hold(3, 1)
cboProduct.AddItem hold(4, 0) & j & hold(4, 1)
cboProduct.AddItem hold(5, 0) & j & hold(5, 1)
cboProduct.AddItem hold(6, 0) & j & hold(6, 1)
txtQuantity.Text = 1
End Sub
Private Sub cmdAdd_Click()
y = cboProduct.ListIndex
j = "$"
Dim selItem
listAr(b, 0) = hold(y, 0)
listAr(b, 1) = hold(y, 1) * txtQuantity.Text
listAr(b, 2) = txtQuantity.Text
listAr(b, 3) = hold(y, 1)
abc = Round(listAr(b, 1), 2)
selItem = listAr(b, 0) & j & abc
List1.AddItem selItem
cboProduct.SetFocus
b = b + 1
End Sub
Private Sub cmdRemove_Click()
If List1.ListIndex >= 0 Then
List1.RemoveItem List1.ListIndex
End If
cboProduct.SetFocus
End Sub
-
Assume that i=the index value of the array element to
delete, and n = the number items. Then:
[/code]
for k = i to n-1
arrayelement(k,0)=arrayelement(k+1,0
next k
arayelement(k,0)=nothing
[/code]
Should work
DerFarm