Question Read text File with Multiple fields

gsoalan

New member
Joined
Oct 17, 2009
Messages
3
Programming Experience
Beginner
I have a text file in this format

VB.NET:
Date	        Time	Ticker	Sector	Open	High	Low	Close	Volume	Ask  AskVol	Bid 	Bid Vol	MidSpread Fact1
20080206	9:30:00	AAPL	45	130.88	130.88	130.88	130.88	294028	130.93	850	130.92	700	130.925	0.500000
20080206	9:30:05	AAPL	45	130.92	130.95	130.82	130.94	17294	130.95	700	130.94	100	130.945	-0.200000
20080206	9:30:10	AAPL	45	130.94	131	130.93	130.99	15567	130.99	700	130.95	100	130.97	-0.692308
20080206	9:30:15	AAPL	45	130.98	131.02	130.95	130.99	7178	131.04	100	130.99	200	131.015	0.000000
20080206	9:30:20	AAPL	45	131	131.13	130.97	131.1	10822	131.17	200	131.04	20	131.105	0.694915
20080206	9:30:25	AAPL	45	131.05	131.1	131	131.01	9104	131.03	200	130.98	100	131.005	-0.904762
20080206	9:30:30	AAPL	45	130.97	131.04	130.94	130.99	5786	131.08	100	130.98	600	131.03	-0.742820
20080206	9:30:35	AAPL	45	131.02	131.03	130.97	130.97	7765	130.99	50	130.97	200	130.98	0.333333
20080206	9:30:40	AAPL	45	130.97	131.03	130.97	131.01	10836	131.02	200	131	5000	131.01	0.516003
20080206	9:30:45	AAPL	45	131.01	131.02	131	131	6634	131.01	180	131	730	131.005	0.200000
20080206	9:30:50	AAPL	45	131	131.06	131	131.05	12395	131.06	700	131.03	120	131.045	-0.600000
20080206	9:30:55	AAPL	45	131.05	131.19	131.04	131.14	6510	131.2	400	131.16	100	131.18	0.000000
20080206	9:31:00	AAPL	45	131.19	131.25	131.15	131.25	3385	131.25	497	131.23	100	131.24	0.826449


Basically I would like to read in this file line by line and separate every every field into a custom variable and then do some processing

So, I would read in the first record and put the data into these fields

date
time
ticker
sector
open
high
ETC

I started coding this using a TEST file that only had two fields name and a number

VB.NET:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Dim FILE_NAME As String = "C:\aaple2.txt"
        Dim FILE_NAME As String = "C:\TEST.txt"

        Dim TextLine As String
        Dim fName As String
        Dim mNum As Integer

        If System.IO.File.Exists(FILE_NAME) = True Then
            Dim objReader As New System.IO.StreamReader(FILE_NAME)
            Do While objReader.Peek() <> -1
                fName = objReader.ReadLine
                'mNum = objReader.ReadLine
                TextBox1.Text = fName
                'TextLine = TextLine & objReader.ReadLine() & vbNewLine
            Loop
            TextBox1.Text = fName
        Else
            MsgBox("File Does Not Exist")


        End If



    End Sub

I got an unhandled exception on this line
mNum = objReader.ReadLine


Thanks
 
Back
Top