VB - How to Tell When Input Reaches End of a Line?

  • Thread starter Thread starter Vik Rubenfeld
  • Start date Start date
V

Vik Rubenfeld

I'm working on a macro that will import a comma-delimited text file into
MSGraph. I'm using this line (inside of a loop) to input each field:

Input #1, IString

The number of fields per line in my text file, can be different from one
line to another.

How can I tell when Input has gotten to the end of a line (that is, has
encountered a carriage return)?

Thanks in advance to all for any info.

-Vik
 
Vik,
I may be wrong but I do believe that with Input# you can't detect a end of
line since it places each comma separated value into the variable and
proceeds to the next.

It would be easier to read one line at a time and then use the Split
function to break up the comma separated values.


--
Regards
Shyam Pillai

Handout Wizard
http://www.mvps.org/skp/how/
 
It would be easier to read one line at a time and then use the Split
function to break up the comma separated values.

That sounds like it would work well. I found a Split method that splits
cells. Is there one that breaks up a string into comma separated values?

-Vik
 
It would be easier to read one line at a time and then use the Split
That sounds like it would work well.

Yup. Look up help on Line Input instead of Input
I found a Split method that splits
cells. Is there one that breaks up a string into comma separated values?

Sub SplitExample()

Dim strTestString As String
Dim strArray() As String
Dim x As Integer

' Deliberately goofy string with a quoted phrase that includes a comma
strTestString = "This,that,the other," & Chr$(34) & "but wait, there's
more" & Chr$(34)
' Show the whole string
MsgBox strTestString

' Split it apart - note that the comma within the quoted phrase is still
treated as a delimiter
strArray = Split(strTestString, ",", -1)

For x = 0 To UBound(strArray)
MsgBox strArray(x)
Next x

End Sub
 
Back
Top