Results 1 to 3 of 3

Thread: let me try again delete and update records

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    10
    I am trying to update and delete records, using Visual Basic, from a file I have called "items.csv"

    I displayed the current records in a listbox and I was wondering how you use VB and delete records from the file I called "items.csv"

    example data in "items.csv"
    item# A B C D
    0142 123 32 12 YES
    1111 111 222 0 NO
    .
    1234 123 123 0 NO
    .
    .
    and so on

    How do you go about deleting item# 1234 in the file item.csv

    can anyone help????

  2. #2
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Yes actually i do.

    Well u have to either rewrite the entire file, excluding that 1 record. Or use the
    open for binary
    method, but you'll have to know the exact lenght of the string.

  3. #3
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    Each of the elements in the listbox has a number associated to it such that if you got the value of listbox.listindex you would find that it is a number from 0 to listbox.listcount - 1.

    This is the line number you want to delete so what you do is simple.

    Code:
    1. Open a temporary file
    2. For each of the items in the list box
        3. If this item is NOT the selected item
            4. Write this line to the temporary file
    5. Next item in the list box
    6. Close the File
    7. Delete the Old File
    8. Rename the temporary file as the Old File
    This is the pseudo-code for it... see if you can work out what the code looks like.

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