Reputation: 13
Can anyone give me any pointers. I have a text file that contains dates and values that have been read into an array and displayed in a ListBox
. I need to be able to add new dates and values to the array as well as checking for existing dates in the array so that I can prompt the user to overwrite or cancel.
The part I'm struggling with (forgive me I'm new to this) is how to replace the value in the array if the user selects to overwrite. The code below is what I'm using to check for the existence of the date in the array and what I need to be able to do is replace the existing value that goes with date and update the ListBox
with the new data.
There are 2 arrays Dates
and Values
that are displayed in the ListBox
If Dates.Contains(Format(DateTimePicker2.Value, "dd/MM/yyyy")) Then
MsgBox("Do You Wish To Overwrite Record?", MsgBoxStyle.YesNo, "Data already exists")
If MsgBoxResult.No Then
Exit Sub
ElseIf MsgBoxResult.Yes Then
Don't know what to do here !!!!!
End If
Upvotes: 1
Views: 2311
Reputation: 77
You need to add something like this in your Else block (if the ListBox indexes are the same than the Dates array)
Dates(ListBox.SelectedIndex) = (your new value)
It's as simple as this, usually. Of course I skipped the recommanded validation, but I guess it will give you a hint of how to code your thing.
Upvotes: 1