How to remove values from an array ?

I want to remove a value from the center of an array
The array holds the value of a listbox
If an item is removed from the listbox then the same value to be removed from the array
The array has a lot of values for calculations
Dim roof() As Variant
ReDim Preserve roof(0 To 50, 0 To 7)
How to do this?
isnoend2001Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
It won't be easy but post your project and I'll see what I can do.
0
isnoend2001Author Commented:
Thanks Martin Liss, but the project is too huge with tons of purchased ocx's
I was thinking I could empty the array then loop the listbox with the removed value
0
Martin LissOlder than dirtCommented:
Sure. You just solved it!
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

isnoend2001Author Commented:
Where I am having a problem is the value in the listbox is removed by clicking remove item.then the array needs updating less the removed item
After giving more thought. I think I only want to reset a few dimintions and leave others. I wrote the code yrs ago when i was reading books titled beginning vb5 and asking questions like "you can't type into a label, then what do you use ? I am attaching an image that shows the values the array holdsarray valuesThe values in the listbox like 10 x 10 = 100 are parsed into columns 5 & 6 in the array the other columns hold Hips, valleys etc
Maybe a better way would be to create another array and copy the values there, leaving out the column with the new values and then back
0
aikimarkCommented:
@isnoend2001

Is this a VB6, VBA, or VB.Net project?
0
isnoend2001Author Commented:
vb6
I think this is the only place for vb6
0
aikimarkCommented:
From your description, it looks like you need to coordinate the removal of an item from both a listbox control and the associated data structure.  Is that an accurate assessment of the problem?

Listbox controls have a Remove method that can remove a single item.

If you are building the contents of your listbox with code, you might find it easier to simply clear the contents of the listbox and then rebuild it.  Your data structure should be able to logically delete/hide items, which would be skipped by the rebuilding routine.
0
aikimarkCommented:
If you need to physically remove data, you should create a routine that loops from the point of 'deletion' to the 'end' of the dimension/array, copying all the items to the lower position.

Such maintenance overhead can be avoided by using collection or dictionary objects.
0
Martin LissOlder than dirtCommented:
Either way would probably work but it's hard to tell without the project.
0
isnoend2001Author Commented:
Most of the program values are referenced from the array the project has about 50 forms and 50 modules and 30 classes many reference the array
0
isnoend2001Author Commented:
example:job cost
0
isnoend2001Author Commented:
Yes items are removed from the listbox by selecting an item and clicking the remove item button. if no item is selected it removes the last item. This is where i am having a problem eg; updating the array
0
GrahamSkanRetiredCommented:
You will have to shuffle the items down before resizing the array:
Sub RemoveItem()
Dim strArray() As String
Dim i As Integer
Dim u As Integer

strArray = Split("one,two,three,six,four,five", ",")
u = UBound(strArray)
For i = 3 To u - 1
    strArray(i) = strArray(i + 1)
Next i
ReDim Preserve strArray(u - 1)
For i = 0 To u - 1
Debug.Print strArray(i)
Next i
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
isnoend2001Author Commented:
Thanks i see what needs to be done
0
isnoend2001Author Commented:
This seems to work:
roof(0 To 50, 0 To 7)
50 rows, 8 columns

Empty Column
Sub RemoveFromArray(Col As Integer)
Dim i As Integer
For i = 0 To UBound(roof)
roof(i, Col) = vbNullString
Next

Remove selected item from listbox
If ListBoxdetail.ListCount > 0 And ListBoxdetail.ListIndex <> -1 Then
 ListBoxdetail.RemoveItem (ListBoxdetail.ListIndex) 'Remove selected item
 End If

Repopulate array
For i = 0 To ListBoxdetail.ListCount - 1
roof(i, Col) = ListBoxdetail.list(i)
Next
This seems to work, will this cause any problems ?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.