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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parsing prob

Status
Not open for further replies.

nicktred

Programmer
Jan 2, 2004
20
GB
HI

im trying to read in csv file adn then import the data into a table.

Everything works so far but before the csv is added i remove the first 6 lines of it except for the first one.

How can i get just the ref no and append it to all records in the csv.
the ref no looks like
ref id: 1234
and then is the data to be included

i am usign the following to import the file

Dim fs As FileSystemObject
Set fs = New FileSystemObject
Dim txtInn As TextStream
Dim txtOut As TextStream
Dim lCounter As Long
Dim sText As String
Set txtInn = fs.OpenTextFile(strInputFileName, ForReading)
Set txtOut = fs.CreateTextFile("c:\test_2.txt", True)
Do While Not txtInn.AtEndOfStream
lCounter = lCounter + 1
sText = txtInn.ReadLine
txtOut.WriteLine sText
End If
If lCounter > 6 Then
txtOut.WriteLine sText
End If
Loop
txtInn.Close
txtOut.Close
Set txtInn = Nothing
Set txtOut = Nothing
Set fs = Nothing



DoCmd.TransferText acImportDelim, "matchdataimportspec", "match_data", "c:\test_2.txt", hasfieldnames - 0


Any ideas?/
cheers

Nick
 
You say, you want to use only the first line and then from 7th line on. Your code:
Do While Not txtInn.AtEndOfStream
lCounter = lCounter + 1
sText = txtInn.ReadLine
txtOut.WriteLine sText
End If
If lCounter > 6 Then
txtOut.WriteLine sText
End If

will print all lines and from the seventh line on it will print them doubled because of the bold line.
Change it to:
Code:
...
If Not txtInn.AtEndOfStream Then
sText = txtInn.ReadLine
txtOut.WriteLine sText
End If
   Do While Not txtInn.AtEndOfStream
        lCounter = lCounter + 1
        If lCounter > 6 Then
            txtOut.WriteLine sText
        End If
   Loop
...

Should get you on the right track

Andreas Galambos
EDP / Technical Support Specialist
(andreas.galambos@bowneglobal.de)
HP:
 
I added incomplete code before i think it shoudl be

Do While Not txtInn.AtEndOfStream
lCounter = lCounter + 1
sText = txtInn.ReadLine
If lCounter = 1 Then
txtOut.WriteLine sText
End If

If lCounter > 6 Then
txtOut.WriteLine sText
End If

Loop

it doesnt seem to print them doubled (do u mean pritn each line twice?)

What i am trying to do is to take part of the string from line one and append i to the front of each line in the csv, is that what the code does? as when i run it it just hangs access.

Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top