First some observations...
- You need to set up the Dialog box
before you display it not afterwards
- As Richard said in his comment - use the correct type for your values
- It looks as if you were a Classic VB or VBA programmer before venturing into VB.NET ... there is no need to process the file line by line nor to use Peek (see below).
- There is a neater way to use the Split function (see below)
- Use the explicit Try and/or TryParse methods rather than CDbl or CInt - they are more robust (see below)
- There is no need to update the textbox text values within the loop - just do that once you have worked out the min and max values
Here is my first attempt at the problem:
Dim textfile As String
Dim openDlg As New OpenFileDialog
openDlg.Filter = "txt files (*.txt)| *.txt|All files (*.*)|*.*"
openDlg.FilterIndex = 1
openDlg.RestoreDirectory = True
If openDlg.ShowDialog() = DialogResult.OK Then
textfile = openDlg.FileName
Dim fileLines() As String = File.ReadAllLines(textfile)
Dim col1 As List(Of Long) = New List(Of Long)()
Dim col2 As List(Of Long) = New List(Of Long)()
Dim col3 As List(Of Double) = New List(Of Double)()
Dim col4 As List(Of Double) = New List(Of Double)()
For Each fileLine As String In fileLines
If fileLine.StartsWith("S") Then fileLine = fileLine.Substring(1)
Dim items() As String = fileLine.Split(New Char() {CChar(vbTab), " "}, StringSplitOptions.RemoveEmptyEntries)
Dim lngRet As Long
Dim douRes As Double
If Integer.TryParse(items(0), lngRet) Then col1.Add(lngRet)
If Integer.TryParse(items(1), lngRet) Then col2.Add(lngRet)
If Double.TryParse(items(2), douRes) Then col3.Add(douRes)
If Double.TryParse(items(3), douRes) Then col4.Add(douRes)
Next
col1.Sort()
col2.Sort()
col3.Sort()
col4.Sort()
MaxvalE.Text = col1.Item(col1.Count - 1).ToString()
MinvalE.Text = col1.Item(0).ToString()
MaxvalN.Text = col2.Item(col2.Count - 1).ToString()
MinvalN.Text = col2.Item(0).ToString()
End If
I say "first attempt" because I would probably carry on to see if I could create a DataTable from the file, or at least introduce a class for the rows in the table so I could encapsulate all of the behaviours (int or double, starts with S or not etc). But this is a working starting point for you.