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).RecordDat e.ToShortDateString
swriCurrent.Write(",")
swriCurrent.Write(OutputRecord(intCount).Temperatu re 'This
should be the average
swriCurrent.WriteLine()
Next
srdCurrent.Close()
End Sub 1 2015
look into regex.split
"Alex" <al**@protexionproducts.com> wrote in message
news:48**************************@posting.google.c om... 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).RecordDat e.ToShortDateString swriCurrent.Write(",") swriCurrent.Write(OutputRecord(intCount).Temperatu re 'This should be the average swriCurrent.WriteLine() Next
srdCurrent.Close()
End Sub This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Steve |
last post by:
Hi all
How would I find out the average date when given a bunch of dates? For
example, I want to find the average length in time from the following dates:...
|
by: Amanda |
last post by:
This is hotel reservation when a departure date is changed manually by
user input ( to a valid date in date format - validity is
checkedsomewhere else), the arrival date is set to the previous date...
|
by: abouddan |
last post by:
Hi all
I am working on an accounting project using MS Access 2000, that demands to calculate many fields in a spesific record.
The problem:
The query I am using returns many records and for each...
|
by: gaga |
last post by:
hi guys,
a part of my program requires me to calculate an average of items that
are sold. the easiest way to do that would be writing a function, but
im having trouble making up the parameters. if...
|
by: Beemer Biker |
last post by:
I cant seem to get that date into any DateTime to make my calculation
directly by subtracting "01-01-0000" from "now".
After reading this:...
|
by: Sedigh |
last post by:
Hi Everybody,
I need to write a macro on my Excel sheet to calculate the average of cells for me. This is the code I have written but the average function is not working.
Can you please let me...
|
by: paeh |
last post by:
hello..can anyone help me. I am beginner in programming. I need to make a system that can calculate moving average.
my system process will be executed according to certain schedule such as daily,...
|
by: SuzK |
last post by:
I am trying to calculate in VBA in Access 2002 a moving average and update a table with the calculations. Fields in my WeeklyData table are
Week Ending (date)
ItemNbr (double)
Sales Dollars...
|
by: denveromlp |
last post by:
Hello,
I'm new to Access and trying to calculate a rolling 12 month average from some time data. Each data point is a date and a measurement taken at that date. As far as I can tell, the only...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |