3 Replies - 1582 Views - Last Post: 26 July 2012 - 08:25 AM Rate Topic: -----

#1 katie1988  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-July 12

How can I remove a line of text from a text file in VB6?

Posted 24 July 2012 - 08:25 AM

I have a search facility where items are displayed in a ListView. These items are read in from a file. When I select an item in the ListView I want to be able to remove it from the text file as well. At the moment, it is is only removed from the ListView but when I search again it still displays so it isn't being deleted from the text file.

Basically my program is a list of products with their barcodes and quantities. The user can search for an item, which is displayed in the listview, then edit it to add or reduce the quantity. When they click save it is written to the file. That is all working fine, but it is now showing the item twice, same barcode and product name and different quantities.

I tried to use the replace function but that is just adding empty lines of text to my file. I have also gotten advice to copy the file and remove the selected item. I'm unsure how to do this. Does anyone have any alternative ways to do this? Here is my code:

Private Sub cmdEdit_Click()
Dim barcode As String
Dim prodNum As String
Dim unknown As String
Dim desc As String
Dim size As String
Dim costPrice As String
Dim retailPrice As String
Dim deptCode As String
Dim dept As String
Dim subDeptCode As String
Dim subDept As String
Dim quantity As String
Dim barcodeYes As String
Dim Number As String
Dim i As Single

ListView1.ListItems.Remove ListView1.SelectedItem.Index

Open "D:\VB\EXPORT PRODUCT FILE.CSV" For Input As #3
Input #3, barcode, prodNum, unknown, desc, size, costPrice, retailPrice, deptCode, dept,      subDeptCode, subDept, quantity, barcodeYes, Number
AddQuantity.Show
AddQuantity.txtName.Text = ListView1.SelectedItem
AddQuantity.txtBarcode.Text = ListView1.SelectedItem.SubItems(1)
AddQuantity.txtQuantity.Text = ListView1.SelectedItem.SubItems(2)
Close #3
End Sub



Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: How can I remove a line of text from a text file in VB6?

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,653
  • Joined: 02-June 10

Re: How can I remove a line of text from a text file in VB6?

Posted 24 July 2012 - 10:12 AM

T#ke a look at the vb.net area as I know I just answered this identical question for someone else. The short answer is you have to rewrite the entire file because you can't replace or delete individual lines of a text file.
Was This Post Helpful? 0
  • +
  • -

#3 Neku  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 268
  • Joined: 21-May 09

Re: How can I remove a line of text from a text file in VB6?

Posted 24 July 2012 - 12:33 PM

as tlhIn`toq said, just save the file every time you edit the listview, that will solve your problem :)
Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

Re: How can I remove a line of text from a text file in VB6?

Posted 26 July 2012 - 08:25 AM

Well, I answered this in the other one too. You really can edit individual lines of a text file. You use Open file for Random instead of open file for input.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1