im creating an address book and well it aint "quite going to plan" im having problems on the 'remove' coding
what i want it to do is when i click on the list box it loads the 'record' from a .dat file and displays it in text boxes on the right but it seems to mess up when i try deleting that "record"
it deletes the record but when i add another record that 'line' in the listbox is blank
for example if i had records 1,2,3 in the listbox and i deleted "record 2" the list box would be first line blank(but when clicked have info for record 1),1(when clicked it be blank) and record 3 would work fine
heres the code im using-
VB Code:
Private Sub Command1_Click() 'REMOVE!! Dim intFile As Integer, add As address On Error GoTo errHandler 'If the listcount is 0, give the user an error msgbox. If List1.ListItems.Count = 0 Then MsgBox "There aren't any entries to delete.", vbExclamation, "Error!": Exit Sub intFile = FreeFile 'Open file, andsave it. Open "C:\book.dat" For Random As intFile Len = Len(add 'Set everything to null. add.fname = "" add.lname = "" add.address = "" 'Put the information in the file. Put #intFile, List1.SelectedItem.Index, add 'Close the file, when you're finished. Close intFile 'Remove the selected item. List1.ListItems.Remove (List1.SelectedItem.Index) Exit Sub 'If there's not a selected item, give the user an error msgbox. errHandler: MsgBox "Please select the name you want to delete in the listbox below.", vbExclamation, "Error!" Exit Sub End Sub
