Results 1 to 2 of 2

Thread: listbox problem..i think

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    1

    Resolved listbox problem..i think

    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:
    1. Private Sub Command1_Click()
    2. 'REMOVE!!
    3.  
    4.     Dim intFile As Integer, add As address
    5.     On Error GoTo errHandler
    6.     'If the listcount is 0, give the user an error msgbox.
    7.     If List1.ListItems.Count = 0 Then MsgBox "There aren't any entries to delete.", vbExclamation, "Error!": Exit Sub
    8.     intFile = FreeFile
    9.     'Open file, andsave it.
    10.     Open "C:\book.dat" For Random As intFile Len = Len(add
    11.         'Set everything to null.
    12.         add.fname = ""
    13.         add.lname = ""
    14.         add.address = ""
    15.  
    16.         'Put the information in the file.
    17.         Put #intFile, List1.SelectedItem.Index, add
    18.     'Close the file, when you're finished.
    19.     Close intFile
    20.     'Remove the selected item.
    21. List1.ListItems.Remove (List1.SelectedItem.Index)
    22.     Exit Sub
    23.    
    24.     'If there's not a selected item, give the user an error msgbox.
    25. errHandler:
    26.     MsgBox "Please select the name you want to delete in the listbox below.", vbExclamation, "Error!"
    27.     Exit Sub
    28. End Sub
    Last edited by baron; Oct 27th, 2005 at 04:55 PM.

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: listbox problem..i think

    Welcome to the Froum Baron

    Thats not normal behaviour for a ListBox.
    This works: List1.RemoveItem (List1.ListIndex)

    BTW, I'm assuming your using a VBA ListBox - which app?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width