Re: Calculate Average by Date from Text File

From: Mark Jones (none.due.to.spam_at_devnullbucket.org)
Date: 11/22/04


Date: Mon, 22 Nov 2004 12:51:21 -0800

look into regex.split

"Alex" <alex@protexionproducts.com> wrote in message
news:4849dbc3.0411221227.40fb5fa4@posting.google.com...
> I have a comma separated text file in the form:
>
> 11/28/2004 12:00:00, 2.78655354
> 11/28/2004 12:00:10, 1.9978
> 11/28/2004 12:00:20, 0.978
> 11/29/2004 12:00:00, 1.98467
> 11/29/2004 12:00:10, 3.005
>
> I would like to be able to read the file and then write just the date
> and the average value to a to an array and then output it to a text
> file. I am not having any problems reading in the file. However, I
> can't figure out how to summarize the raw data into an array or
> structure or collection. The data should look like this:
>
> 11/28/2004 1.9207844
> 11/29/2004 2.494835
>
> I would imagine it requires a for loop of some sort. I have tried for
> a while but with no luck. Hopefully, someone can answer this for me.
> Here is what I have so far:
>
> Private Sub btnWriteOutputFile_Click(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles btnWriteOutputFile.Click
> Dim srdCurrent As System.IO.StreamReader
> Dim intInputCount, intOutputCount, intTempCount As Integer
> Dim strLine As String
> Dim strFields() As String
> Dim chrDelimiter() As Char = {ToChar(",")}
> Dim swriCurrent As System.IO.StreamWriter
> ofdInputFile.Title = "What file do you want to summarize"
> ofdInputFile.ShowDialog()
> srdCurrent = New System.IO.StreamReader(ofdInputFile.FileName)
> strLine = srdCurrent.ReadLine
>
> Do Until strLine = Nothing
> ReDim Preserve OutputRecords(intInputCount)
> strFields = strLine.Split(chrDelimiter)
> OutputRecords(intInputCount).RecordDate =
> ToDateTime(strFields(0))
> OutputRecords(intInputCount).Temperature =
> ToSingle(strFields(1))
> intInputCount += 1
> strLine = srdCurrent.ReadLine
> Loop
> For intOutputCount = 0 To OutputRecords.GetUpperBound(0)
>
> Summarizing Code Here ?????
>
> Next
> sfdOutputFile.Title = "Choose File or Name File to save
> summary to"
> sfdOutputFile.ShowDialog()
> swriCurrent = New
> System.IO.StreamWriter(sfdOutputFile.FileName)
> For intOutputCount = 0 To OutputRecords.GetUpperBound(0)
> swriCurrent.Write(OutputRecord(intCount).RecordDate.ToShortDateString
> swriCurrent.Write(",")
> swriCurrent.Write(OutputRecord(intCount).Temperature 'This
> should be the average
> swriCurrent.WriteLine()
> Next
>
> srdCurrent.Close()
>
> End Sub



Relevant Pages

  • Calculate Average by Date from Text File
    ... and the average value to a to an array and then output it to a text ... can't figure out how to summarize the raw data into an array or ... a while but with no luck. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Need Help deleting record from text file
    ... I'm guessing that you'll have no problems getting the filenames from the folder into a String array, so here's some code to show you how to sort such an array and how to search it for a specific item. ... Private Sub ShellSortAs String, ... As Long, ByVal Ub As Long, ByVal cmp As Integer) ...
    (microsoft.public.vb.general.discussion)
  • Re: Generic Userform class
    ... That's a new idea on me, a public array of withevents Forms class's, as you ... Public myFormsAs FormClass ' not as New ... Private Sub UserForm_Initialize ... > Public WithEvents objForm As MSForms.UserForm ...
    (microsoft.public.excel.programming)
  • SUMMARY: A1000 and space
    ... Nathan Dietsch ... I am still waiting for new battery which i ordered to make sure caching isn't the issue.(I will summarize if it works) ... The healthck should show battery information. ... On a really large disk array, ...
    (SunManagers)
  • RE: Make all variable values in a Array equal to 0
    ... Dim var1 As Single ... Private Sub btnApply_Click ... just figured using an Array would reset the variables. ... Lether Seats (CheckBox1 and var1) ...
    (microsoft.public.excel.programming)