[RESOLVED] Removing an item from a array
I know this has been up in earlier posts but I just couldn't figure it out.
My array is a structure like this:
VB Code:
Public Structure Appointment
Public Counter As Integer
Public Year As Integer
Public Week As Integer
Public Weekday As Integer
Public Frequens As String
Public Where As String
Public Note As String
End Structure
Public MyAppointment() As Appointment
My objective is to remove an item in that array.
I do it like this (where intindex is the item I want to remove):
VB Code:
For i = intIndex To MyAppointment.Length - 1
MyAppointment(i) = MyAppointment(i+1)
Next i
Ok. So far so good. Now I only need to delete the last item of my array. Otherwise the length of my array is still the same (and the two last items of the array will be identical)
How can I do that ?
Anwin
Re: Removing an item from a array
You do it by not using an array in the first place. If you want to be able to add and remove items then you should use a collection. The most basic collection is the ArrayList, but you should use the one that's most appropriate to your circumstances.
Re: Removing an item from a array
You are probably right that I should have used Arraylist in the first place.
However I found a solution that was quite simple. I already have a variable that counts when I add an item to my array. I call my variable NumberOfItems.
VB Code:
NumberOFItems -= 1
ReDim Preserve MyAppointment(NumberOFItems)