how to get the highest date from txt file and how to get the max value by line

maq

New member
Joined
Jan 19, 2012
Messages
2
Programming Experience
Beginner
hi all

how to get the highest date of txt file

how to get the max value of arrayForTheLine(3) in 14 lines( that's mean count highet date line - 14) and when i get the max how to get the date of the line that has the max value

this the file

<ticker>,<date>,<open>,<high>,<low>,<close>,<vol>
aaaa,20100919,19.8,19.95,19.7,19.7,222643
aaaa,20100918,20.05,20.1,19.75,19.9,174402
aaaa,20100915,19.8,19.9,19.65,19.9,351537
aaaa,20100914,19.8,19.9,19.6,19.8,696911
aaaa,20100906,19.75,19.9,19.55,19.65,772510
aaaa,20100905,20.2,20.45,19.75,19.85,875499
aaaa,20100904,20.8,20.9,20,20.2,778366
aaaa,20100901,19.4,20.9,19.4,20.65,496819
aaaa,20100831,19.55,19.7,19.45,19.45,163574
aaaa,20100830,19.5,20.3,19.4,19.8,455908
aaaa,20100829,20.15,20.15,19.3,19.6,476880
aaaa,20100828,21,21,20.05,20.1,395201
aaaa,20100825,20.8,21.35,19.1,20.85,568433
aaaa,20100824,22.15,22.5,21,21,198542
aaaa,20100823,22.9,22.9,21.6,22,309772
aaaa,20100822,22.95,22.95,22.65,22.8,120463
aaaa,20100821,23,23.25,22.5,22.85,299538
aaaa,20100818,22.8,23.45,22.5,22.95,906171
aaaa,20100817,22.9,23.3,22.5,22.75,514636
aaaa,20100816,22,23.5,21.55,22.95,1580438
aaaa,20100815,22.2,22.5,21.45,22.1,616626
aaaa,20100814,22.5,23.7,21.6,22,1795921
aaaa,20100811,20.7,22.9,20.55,22,1617880
aaaa,20100810,20.7,21.15,20.5,20.85,885246
aaaa,20100809,20.85,21,20.75,20.9,106036
aaaa,20100808,21.15,21.35,20.85,20.95,284957
aaaa,20100807,20.9,22,20.9,21.3,932640
aaaa,20100804,21,21.15,20.55,20.95,212297


i try this code


Dim maxtxtfile As Date = Date.Parse((maxtxtfile))
Dim comboText As String = ComboBox2.SelectedItem.ToString()
Dim maxdate As Date
Dim maxHigh As Double = 0
For Each line As String In Lines
Dim SplitString As String() = line.Split(","c)
If (SplitString.Length > 1) And (SplitString(0).Equals(comboText)) Then
Try
maxtxtfile = If(Date.TryParse(SplitString(1), Nothing), _
CDate(SplitString(1)), CDate(New Date(Val(SplitString(1).Substring(0, 4)), Val(SplitString(1).Substring(4, 2)), Val(SplitString(1).Substring(6, 2))).ToShortDateString))
If maxtxtfile > DateAdd("d", -14, Date.Today()) Then
If Double.Parse(SplitString(3)) > maxHigh Then
maxHigh = Double.Parse(SplitString(3))
maxdate = maxtxtfile
End If
End If
Catch
End Try
End If
Next
TextBox1.Text = maxHigh
TextBox2.Text = maxdate
End Sub



but not what i am looking for


thank you for your help


 
Insert the fundamental code snippet 'Read a Delimited Text File' into your code. How to: Insert Snippets Into Your Code (Visual Basic) (shortcut: filparsetext+TAB)
You can skip the header line by making a call to ReadFields before looping the data lines.
High value is in fields(3) and date in fields(1). As you have discovered you have to convert the string to a number data type to check its numeric value. About date, do you actually need to convert that to a Date value then back to a string? If you do you can use Date.ParseExact method.
 
hi

i need the max ,min, avarage, for the 24 lines that lines counted from the line that contain the max date

so i get the code for the max date for in the txt file

this code used for both if txt file sorted by Ascending or by Descending

Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.IO
Imports System
Imports System.Text.RegularExpressions

Public Class Form1
Dim Lines As String()


Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Lines = File.ReadAllLines("c:\" + ComboBox1.SelectedItem.ToString() + ".txt")
Dim list As New List(Of String)
Dim notTricker As Boolean = False
For Each line As String In Lines
Dim SplitString As String() = line.Split(","c)
If SplitString.Length > 1 Then
If Not (list.Contains(SplitString(0))) Then
If notTricker Then
list.Add(SplitString(0))
ComboBox2.Items.Add(SplitString(0))
Else
notTricker = True
End If
End If
End If
Next
End Sub



'this code read the max but as Integer for the all arrayForTheLine 1 or 2 or 3 or 4 etc... for any direction or place in the record

Dim comboText As String = ComboBox2.SelectedItem.ToString()
Dim strDate As Integer = 0
For Each line In Lines
Dim arrayForTheLine = line.Split(","c)

Try
If arrayForTheLine(1) > strDate Then
strDate = Integer.Parse(arrayForTheLine(1))
TextBox5.Text = strDate.ToString
End If
Catch
End Try
Next
End Class





thank you
 

Attachments

  • b2.gif
    b2.gif
    92.1 KB · Views: 24
  • b2.gif
    b2.gif
    90.8 KB · Views: 26
Last edited:
Back
Top