views:

133

answers:

3

I am using Visual Basic 2008, and I am making a simple meeting planner program. The data stored for each day is stored into an array with three fields:

calendars.Days
calendars.ToD
calendars.Appointment

Days stores the selected day corresponding to the MonthCalendar object of the entry.
ToD is the time of day selected by a combobox of times for the appointment.
Appointment is whatever description in a textbox the appointment is given.

Whenever a day is selected on the MonthCalendar object, it loads all of the data from that day that is in the array and displays it in a listbox called lstResult. What I am trying to do is, when I press the delete key on a selected entry in the listbox, it deletes that entry in the array and the listbox. The listbox part is easy, I just need help on deleting the selection from the array.

Anyone got any ideas on how to go about this? Note that I am not much of an expert on Visual Basic so some things might need a little explanation to them.

A: 

In general, the Array interface does not support deleting specific objects. To do that, you should use some sort of list (ArrayList, for example).

Tal Pressman
+1  A: 

If you want to use an array, you could change your design to include a flag to mark those items that are "deleted"; you could think on them as "logically deleted" (a bonus is that you could recover something you had previously deleted) and in the view just filter those that are not marked. Get the idea? Just my $0.02.

+1  A: 

Just as a suggestion, I would recommend creating a CalenderAppointment class and using a generic list of the CalenderAppointment class. By doing this you will receive all the goodness of Linq and generics.

dim myAppointments as new List(of CalenderAppointment)

public sub AddAppointment(appointment as CalenderAppointment)
    myAppointments.Add(appointment);
end sub

public sub RemoveAppointment(appointment as CalenderAppointment)
    myAppointments.Remove(appointment);
end sub


public class CalenderAppointment

    public Appointment as string
    public Days as integer
    public TimeOfDay as DateTime

end class

The Appointment, Days and TimeOfDay should really be made into properties, but for simplicity sake you can use public variables

Take a look at http://msdn.microsoft.com/en-us/library/w256ka79(VS.80).aspx for more info on generics

Mike737