Solved

how to delete one line of text

Posted on 2002-05-24
4
140 Views
Last Modified: 2010-05-02
I have a program that records an invoice. I need to have code to delete one line based upon the first field of the line. That is , the invoice number.
example:

"114778  ","4.15     ","160.00 ","8      ","dj                  ","   "
"114597  ","4.12     ","187.50 ","9.375  ","kachina             ","   "
[["115170  ","4.12     ","180.00 ","9      ","kachiina            ","   "]]
"115290  ","4.17     ","191.25 ","9.5625 ","kachina             ","   "
"115429  ","4.24     ","240.00 ","12     ","kachina             ","   "
"115228  ","4.12     ","78.75  ","3.9375 ","kales               ","   "
"114973  ","4.3      ","150.00 ","7.5    ","sup shut            ","   "

I want to delete iinvoice number [["115170..."]] and all data in that line and leave the other lines alone.
 
The line to delete is :

[["115170  ","4.12     ","180.00 ","9      ","kachiina            ","   "]]

This program is written as a sequencial data in vb4
0
Comment
Question by:hjaycox
  • 2
  • 2
4 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7033848
You will have to read the whole file and write it out to a new file, skipping the invoice you wish to delete.  If you need code let me know.

Anthony
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 200 total points
ID: 7033861
If we assume that the invoice file is in a folder called Invoices and is called Invoice.txt then here is the code:

Sub DeleteInvoice(ByVal DeleteInvoiceNumber As String)
Const InvoiceFileName = "c:\Invoices\Invoice.txt"
Const TempFileName = "c:\Invoices\Temp.txt"
Dim InHandle As Integer
Dim OutHandle As Integer
Dim InvoiceNumber As String
Dim a As String, b As String, c As String, d As String, e As String

InHandle = FreeFile
Open InvoiceFileName For Input As #InHandle

OutHandle = FreeFile
Open TempFileName For Output As #OutHandle

Do While Not EOF(InHandle)
   Input #InHandle, InvoiceNumber, a, b, c, d, e
   If InvoiceNumber <> DeleteInvoiceNumber Then
      Write #OutHandle, InvoiceNumber, a, b, c, d, e
   End If
Loop
Close InHandle
Close OutHandle
Kill InvoiceFileName
Name TempFileName As InvoiceFileName

End Sub

You would call it as follows (notice that I am spelling it exactly as in the file, you can trim it or convert it to a number to avoid this):

DeleteInvoice "115170  "

Anthony
0
 
LVL 4

Expert Comment

by:mcoop
ID: 7034064
Of course you could just 'clear' the line, and that would save reprocessing the whole file until later (end of day/week/mnth), when you can do a cleanup to compact the file (remove the blank lines).

This assumes your program will handle blank lines gracefully - you may need to do a little extra coding, but the end result is simpler than recompacting the file each time...

If your code is tidy enough, you can also go back and re-use the empty 'records' when adding new lines - or-

To be even more sophisticated - perhaps you can negate the invoice number ( invNum = 0-invnum ), to indicate that the record is no longer 'active'.  This allows you to see 'deleted records' after they have been posted - and undo the deletion if necessary (restore the number to it's original value ( invNum = abs(invNum) ).

Carry on !
0
 
LVL 4

Expert Comment

by:mcoop
ID: 7034069
Also - I the occurrence of embedded 'white space' in variable values is not good form...  you may prefer to pack these fields for consistency.

e.g. (shown as XXX vs original text record above)

115170  ","4.12XXXXX","180.00X","9XXXXXX","kachiinaXXXXXXXXXXXX","  
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Help in WHSCRIPT 9 41
Access 2016 VB code 9 86
VB6 - Compare and highlight cell not the same 3 33
Visual Studio 2005 text editor 10 18
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now