concatenating Line Input

  • Thread starter Thread starter LMC
  • Start date Start date
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
 
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
 
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.
 
Back
Top