concatenating Line Input

L

LMC

Using the Line Input method I am reading a CSV text file that originated from
a table with paragraph returns within single cells. The CSV format places the
embedded paragraphs on seperate lines and I am trying to reconcatenate the
embedded returns while importing the content into Access 2003. I get stuck
with the nested loop and If-Then-Else logic when attempting to get the code
to concatenate the last line between quotes.

A simplified CSV example looks similar to this where rows 3 thru 5 would be
concatenated into row 2 which would become "f" "g" "h" & "i" in the third
field with paragraphs returns between each letter.
1, "a", "b", "c"
2, "d", "e", "f
3, g
4, h
5, i"
6, "x", "y", "z"


Here's the code in it's current state...
Dim strRow as String, intF as Integer, strLine as String
'code deleted for brevity that opens the text file and reads column names
strRow = ""
Do While EOF(intF) = False
Line Input #intF, strLine
If Not Right (strLine, 1) = char(34) Then
strRow = strRow & strLine & Char(13)
Loop
Else
strRow = strLine
End If
'code deleted for brevity that splits strRow and writes into field
values
strRow = ""
Loop

I'd appreciate any help in modifying the code to perform my need.
LMC
 
K

Ken Snell

Try this modified code structure:

Dim strRow as String, intF as Integer, strLine as String
Dim blnFullLine As Boolean
'code deleted for brevity that opens the text file and reads column
names
strRow = ""
blnFullLine = False
blnBuilding = False
Do While EOF(intF) = False
Line Input #intF, strLine
If Right (strLine, 1) = char(34) Then
strRow = strRow & strLine & Char(13)
blnFullLine = True
Else
strRow = strRow & strLine
blnFullLine = False
End If
If blnFullLine = True Then
'code deleted for brevity that splits strRow and writes into field
values
strRow = ""
End If
Loop
 
L

LMC

Ken, your suggestion of adding the boolean variable did the trick; although I
had to swap the placement of the two strRow statements for it to work. Many
thanks; I had spent all day trying to figure that out on my own and wasn't
getting it.
 
K

Ken Snell

Sorry about the misplacement of the strRow lines, but glad you figured it
out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

no errors- no input 0
update db, no errors , no changes 6
insert problems 1
PLEASE HELP, insert 0
Rid the Immediate Window Call 10
parse a text file 1
Line Input not finding Chr10 or 13 8
Sample code to be fixed! 0

Top