Line Input

B

Bob Barnes

line input# will pull in a WHOLE line into one variable, and then you must
write your own code to parse out the data....

Tips on how to handle any comma, apostrophe, double-quotes with a pair of
double-quotes?? IE...

"Fred","Smith", "Fred's info"
"John","Jones", "John's info
with a return in it"

...or..


"Bob Smith","Acme's "Clothes", Inc."

I use code like..
Open "C:\Bob\" & Y For Input As iNumOne
Set Z = CurrentDb
Set RS = Z.OpenRecordset("FromCSV")
Do Until EOF(iNumOne)
Input #iNumOne, vSvc, vCust, vTypeSvc, vInvV, vStore, vQty '---> Declared
at top of module
With RS
.AddNew
!SvcDate = vSvc: !Cust = Trim(vCust): !TypeSvc = Trim(vTypeSvc)
!InvVesco = Trim(vInvV): !Store = Trim(vStore): !QTY = Trim(vQty)
.Update
End With
Loop



TIA - Bob
 
A

Albert D. Kallal

somting like:

Public Sub test23()

Dim vArr As Variant
Dim intF As Integer
Dim strLine As String
Dim deLim As String
Dim str As Variant
Dim i As Integer

deLim = "," & Chr(34) ' ," is our delim
intF = FreeFile()
Open "c:\t.txt" For Input As intF

Do While EOF(intF) = False
Line Input #intF, strLine
vArr = Split(strLine, deLim)
For i = 0 To 2
str = vArr(i)
If Left(str, 1) = Chr(34) Then
str = Mid(str, 2)
End If
str = Left(str, Len(str) - 1)
Debug.Print "field" & i & " = " & str
Next i
Debug.Print

Loop

End Sub


If I give the above an input file of:

"Fred","Smith","Fred's info"
"John","Jones","John's info"
"Bob Smith","Acme's "Clothes", Inc.","3rd value"

The output is:

field0 = Fred
field1 = Smith
field2 = Fred's info

field0 = John
field1 = Jones
field2 = John's info

field0 = Bob Smith
field1 = Acme's "Clothes", Inc.
field2 = 3rd value

You have to check if your delim has a space after the comma, or not.

If this data being exported by some program, then the data is assumed to be
surrounded by ", it is not consistent that way, then you not be able to
parse this data with certain.
 
B

Bob Barnes

Albert - We discussed this recently.

It will give me some interesting code-testing.

Any other thoughts on trapping a carriage return/ linefeed..I can let the
User know there's a text file carriage return/ linefeed with "...subscript
out of range.."

Thank you - Bob
 
A

Albert D. Kallal

Any other thoughts on trapping a carriage return/ linefeed..I can let the
User know there's a text file carriage return/ linefeed with "...subscript
out of range.."

I not sure what you mean by above?

Line Input will pull all data until the end of the line......
 
B

Bob Barnes

Albert - We had discussed the problem w/ a carriage return because it forces
a new line.

Bob
 

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

Top