Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I cut annotaions off csv-files???

Status
Not open for further replies.

mooneater

Programmer
Jul 2, 2003
7
0
0
DE
Hi all!

I get csv-files that look like this...

**********Cancelled Cheques Report**********
From Date|To Date|Customer No|Customer Name|Dr Account No|Dr Cur|Beneficiary|Order Ref|Payment Ref|Payment Detls|Batch No|Cheque No|Amount|Cur|Country|Cheque Date|Cancelled Date
20030601|20030620|2077253|Default customer |207725300|EUR|CHEOPS SA TEST |null|6150100617|TEST CHEOPS SPANIEN 03.06.03 |DD10100019|1000017|5,005.00|EUR|ES|04/06/2003|10/06/2003
20030601|20030620|2077253|Default customer |207725300|EUR|TEST BENEFICIARY |IGF 10 BGM|6157717115|CHEOPS/EDI/005 HUF0521005 |DD10100151|1000021|320,705.00|EUR|ES|10/06/2003|20/06/2003
20030601|20030620|2077253|Default customer |207725300|EUR|MIKA HAEKINNEN |null|6159614854|CHEOPS/DTAZV/005 |DD10100163|1000024|320,305.00|EUR|ES|10/06/2003|20/06/2003
20030601|20030620|2077253|Default customer |850004300|AUD|TEST BENEFICIARY |IGF 10 BGM|6157717270|CHEOPS/EDI/020A HUF0521020A |DD10100349|100061|808.70|AUD|AU|20/06/2003|20/06/2003
20030601|20030620|2077253|Default customer |207725300|EUR|CHEOPS SARL TEST |null|6150100619|TEST CHEOPS FRANKREICH 03.06.03 |DD10100021|100101|7,007.00|EUR|FR|04/06/2003|10/06/2003
20030601|20030620|2077253|Default customer |207725300|EUR|TEST BENEFICIARY |IGF 10 BGM|6157717251|CHEOPS/EDI/012 HUF0521012 |DD10100324|100128|712.70|EUR|DE|19/06/2003|20/06/2003
End6

How can I get rid off the first and last line in that ???
('**********Cancelled Cheques Report**********', and 'End6')
 
Here is the code you need:

Function RemoveHeaderAndFooter(ByVal strOldFileName As String, _
ByVal strNewFileName As String) As Variant

'function removes header and footer from stroldldFileName
'creating strNewFileName and returning an array of the record count and the removed header and footer


Dim strLineOld As String 'Current line
Dim hFileOld As Long 'Handle on old file
Dim hFileNew As Long 'Handle on new file
Dim intI As Integer 'Counter
Dim strHeader As String 'header removed
Dim lngLineCountOld As Long 'recordcounter

'set up error handler
On Error GoTo ProcError

'get file handles
hFileOld = FreeFile
hFileNew = FreeFile + 1

'open up files
Open strNewFileName For Output As hFileNew
Open strOldFileName For Input As hFileOld

'get header from first line
Line Input #hFileOld, strLineOld
strHeader = strLineOld


Do Until EOF(hFileOld)
'get the next line of old file
'and write it to new file (except last line)
Line Input #hFileOld, strLineOld
lngLineCountOld = lngLineCountOld + 1
if EOF(hFileOld) = false then
Print #hFileNew, strLineOld

end if
Loop
RemoveHeaderAndFooter = Array(lngLineCountOld, strHeader, strLineOld)

ProcExit:
'close files
Close hFileOld
Close hFileNew
DoCmd.Echo True
Exit Function
ProcError:
DoCmd.Echo True
MsgBox Error(Err)

Resume ProcExit


End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top