Results 1 to 5 of 5

Thread: Deleting a string from a textfile

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2002
    Location
    South West UK
    Posts
    245

    Deleting a string from a textfile

    Hello,

    the scenario is...

    I have a listbox which is populated from a textfile. When the user double clicks an item in the listbox the value is put in a textbox to indicate that this is the value to delete from the list.

    Does anyone have a snippit of code which looks for the value in the an array and delets it if found, then rewrites the array to the textfile?

    Any help really appreciated.
    A lowly programmer.

    http://www.sentinalgroup.com

  2. #2
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    I'd use the Replace() function

    replace the string, then save the array to text file
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: Deleting a string from a textfile

    Originally posted by HELPmyVB
    Does anyone have a snippit of code which looks for the value in the an array and delets it if found, then rewrites the array to the textfile?
    What array? The ListBox.List array?

    If so:

    VB Code:
    1. List1.RemoveItem List1.Selected

    (off the top of my head, I can't check right now, but that should be close)
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Then, to rewrite it to the text file, would depend on the format you have it in there. If it's just:

    Item
    Item
    Item
    Item
    Item

    Then:

    VB Code:
    1. Dim i As Integer, iFF As Integer
    2.  
    3.   iFF = FreeFile
    4.   Open "C:\yourfile.txt" For Output As #iFF
    5.     For i = 0 To List1.ListCount
    6.       Print #iFF, List1.List(i)
    7.     Next
    8.   Close #iFF
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: Deleting a string from a textfile

    Originally posted by HELPmyVB
    Hello,

    the scenario is...

    I have a listbox which is populated from a textfile. When the user double clicks an item in the listbox the value is put in a textbox to indicate that this is the value to delete from the list.

    Does anyone have a snippit of code which looks for the value in the an array and delets it if found, then rewrites the array to the textfile?

    Any help really appreciated.
    not sure i understand the question, but this will delete a searchstring from an array

    VB Code:
    1. arrOne = split(replace(join(arrTwo,vbcrlf),vbcrlf & strSearch & vbcrlf ,vbcrlf),vbcrlf)

    untestested, but should give you the idea

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