I'm trying to delete a record from an array in VB.Net but I can never get it to delete the correct one
In my code, intPosition is the position where the desired record I want to delete is. Customers is the name of the 3D array and NumberOfCustomers can be treated as the size of the array.
If MsgBox("Are you sure you want to delete this record?", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
NumberOfCustomers -= 1
For i = intPosition + 1 To NumberOfCustomers
Customers(i - 1) = Customers(i)
Next
NumberOfCustomers -= 1
ReDim Preserve Customers(NumberOfCustomers)
Call SaveCustomer()
End If
Please could someone amend or find similar code for this in VB.NET.
Thanks
List(Of T)or something better suited to the types of things you are trying to do.List(Of Customer)(which will take all of 15 mins to learn about)Customers.RemoveAt(indexToRemove)is all you needMessageBoxButtons. It should beMsgBoxStyle.MessageBoxButtonsenum in theSystem.Windowsnamespace, although it should be used with theMessageBoxclass and not with theMsgBoxVB function.