File Input Newbie

  • Thread starter Thread starter Lisa Henkel
  • Start date Start date
L

Lisa Henkel

Hi.

What's the best way to do file input, if you are particularly
interested in reading numbers from columns 26-37 in a text file?

Thanks,

Lisa
 
Lisa,

the following seems best to me if I understand what you want to do.
Assuming that you have a text file, each line having a CR/LF (newline) at
the end and wanting to get chars 26-37

The following will do that.

HTH,

Shane

'read and process txt file one line at a time
Public Sub ReadFromFile(ByVal strTextFilePath As String)
Dim strmInfile As New System.IO.StreamReader(strTextFilePath)
dim strLine as string
dim S as string

Me.Cursor.Current = Cursors.WaitCursor

'read line
strLine = strmInfile.ReadLine

While Not strLine Is Nothing
Try

s=strLine.substring(25,11) 'read chars 26-37

'YOU DO SOMETHING WITH S

'get next line
strLine = strmInfile.ReadLine
Catch ex As System.Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "ERROR Reading
file")
Me.Cursor.Current = Cursors.Default
exit Sub
Finally
strmInfile.close
End Try
End While

strmInfile.Close()
Me.Cursor.Current = Cursors.Default
End Sub
 
Followup,

Lisa if this is a Comma Separted Text file then you would need to read a
line
then use the string.split(",") to get the line into an array and then access
items 26-37

Shane
 
Back
Top