Best way to remove data from text file in VB6?


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
<\code>
 
Thanks

If you enjoyed this post, subscribe for updates (it's free)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.