|
-
Oct 27th, 2005, 04:34 PM
#1
Thread Starter
New Member
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:
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
Last edited by baron; Oct 27th, 2005 at 04:55 PM.
-
Oct 27th, 2005, 04:44 PM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|