Question Delimited file read and sort/comparison query

wmglobal

New member
Joined
Apr 28, 2011
Messages
1
Location
Coffs Harbour
Programming Experience
Beginner
Hi all

I'm a relative beginner with regard to VB.Net (currently using Visual Studio 2010).

I'm trying to create a program that will look at strings of data about currency trades. An example of the test data I have follows:

Forex Historical Data
DATE;TIME;VOLUME;OPEN;CLOSE;MIN;MAX
03/08/2003;00:00:01;53;.6521;.6516;.6496;.6523
04/08/2003;00:00:01;19062;.6516;.6466;.6426;.6528
05/08/2003;00:00:01;19088;.6468;.6479;.6399;.6495
06/08/2003;00:00:01;17386;.6478;.6482;.646;.6514
07/08/2003;00:00:01;23047;.6482;.6507;.6438;.6526
08/08/2003;00:00:01;14238;.6509;.6513;.6491;.6538
10/08/2003;00:00:01;47;.6513;.6515;.651;.6526
11/08/2003;00:00:01;15125;.6515;.6577;.6501;.6596
12/08/2003;00:00:01;15280;.6577;.6557;.6546;.6611
13/08/2003;00:00:01;16554;.6558;.658;.6521;.6587
14/08/2003;00:00:01;11747;.658;.6565;.6546;.6592
15/08/2003;00:00:01;9840;.6566;.6596;.6554;.6606

What I'm needing to do is

open a file containing data like above and find the date, day of the week and lowest closing price and then date, day of the week and highest closing price from this.

I've made some starts as per below (and please forgive all the comments and mess but trying different things as I go).

I'm stuck with:

a) is there a way to remove the first two lines from the file as they are not required - these are always present in any data dumps I can get from the site in question.

b) See code example below and particularly the area with Red comments.



Private Sub OpenFileToolStripMenuItem_Click(ByVal sender As _
System.Object, ByVal e As _
System.EventArgs) Handles _
OpenFileToolStripMenuItem.Click, _
OpenButton.Click

'Open user file - allow user to specify file to open
Dim ResponseDialogResult As DialogResult
'Dim FileName As String
'Dim FileLoadString As String
Dim LoadArray() As String
'Dim CounterInteger As Integer = 0
'Dim RemoveLinesInteger As Integer = 2
Dim CloseDate As String
Dim ClosePrice As String
Dim LowCloseDate As String = CStr(Today())
Dim LowClosePrice As String
Dim HighCloseDate As String
Dim HighClosePrice As String

'Check if file is already open
'If FileStreamReader IsNot Nothing Then
' FileStreamReader.Close()
'End If

'Set up and display Open File dialog
'With OpenFileDialog1
' .InitialDirectory = Directory.GetCurrentDirectory()
' .Title = "Select File or Directory for File"
' 'Display Open File Dialog box
' ResponseDialogResult = .ShowDialog()
'End With

''Check user didn't select cancel button
'If ResponseDialogResult <> DialogResult.Cancel Then
' 'Open file
' FileStreamReader = New StreamReader(OpenFileDialog1.FileName)
'End If
''load raw data into array
'Do Until FileStreamReader.Peek = -1
' FileLoadString = FileStreamReader.ReadLine()
' LoadArray = FileLoadString.Split(New Char() {";"c})

' CounterInteger += 1
'Loop
''DataListBox.Items.Add(LowCloseDate & "" & LowClosePrice) --test line

''close
'FileStreamReader.Close()
''calculate days of data available.
'CounterInteger -= RemoveLinesInteger
'DaysDataTextBox.Text = CounterInteger.ToString()
''DaysOfData()

With OpenFileDialog1
.InitialDirectory = Directory.GetCurrentDirectory()
.Title = "Select File or Directory for File"
'Display Open File Dialog box
ResponseDialogResult = .ShowDialog()
End With

Try
FileTextFieldParser = New TextFieldParser(OpenFileDialog1.FileName)
FileTextFieldParser.TextFieldType = FieldType.Delimited
FileTextFieldParser.SetDelimiters(";")
Catch ex As Exception
MessageBox.Show("Cannot read file: " & OpenFileDialog1.FileName, _
"Error")
End Try

Do While Not FileTextFieldParser.EndOfData
LoadArray = FileTextFieldParser.ReadFields()
?????????????? This is where I am getting stuck as I have to take two pieces of data from the file i.e. date and the close price and compare these values for each line of data to come up with results like:

4/8/2003 Monday $0.6466 ---> This is the lowest closing price
15/8/2003 Friday $0.6596 ---> This is the highest closing price
Else
MessageBox.Show("No more records", "End of data")
End If
End Sub

_______

I know the code is a bit of a mess but as I said, only trying things and then commenting them out if they don't work.

Any suggestions as to how I go about this as I'm stuck with the points I've mentioned and where to go from here. Not sure I've explained it fully but hopefully someone will be able to follow and can provide some tips.

Regards

WM
 
Back
Top