Option Explicit
Public Sub stats()
Dim intFN As Integer
Dim strLine As String
Dim strParsed() As String
Dim dblSums(8 To 15) As Double
Dim dblAvgs(8 To 15) As Double
Dim dblVariances(8 To 15) As Double
Dim lngCount As Long
Dim lngColumns(1 To 4) As Long
Dim strFilename As String
lngColumns(1) = 8
lngColumns(2) = 11
lngColumns(3) = 12
lngColumns(4) = 15
Dim lngLoop As Long
Const CSVpath As String = "C:\Users\Mark\Downloads\"
'1gl-Factory-Low-SNR-Power-Level-.csv"
intFN = FreeFile
strFilename = Dir(CSVpath & "*.csv")
Do Until Len(strFilename) = 0
Open CSVpath & strFilename For Input As #intFN
Do Until EOF(intFN)
Line Input #intFN, strLine
strParsed = Split(strLine, ",")
'(I, L, M, N, P) = 9, 12, 13, 15 with one origin
For lngLoop = 1 To 4
dblSums(lngColumns(lngLoop)) = dblSums(lngColumns(lngLoop)) + Val(strParsed(lngColumns(lngLoop)))
Next
lngCount = lngCount + 1
Loop
Close #intFN
strFilename = Dir()
Loop
For lngLoop = 1 To 4
dblAvgs(lngColumns(lngLoop)) = dblSums(lngColumns(lngLoop)) / lngCount
Next
strFilename = Dir(CSVpath & "*.csv")
Do Until Len(strFilename) = 0
Open CSVpath & strFilename For Input As #intFN
Do Until EOF(intFN)
Line Input #intFN, strLine
strParsed = Split(strLine, ",")
For lngLoop = 1 To 4
dblVariances(lngColumns(lngLoop)) = dblVariances(lngColumns(lngLoop)) + (dblAvgs(lngColumns(lngLoop)) - Val(strParsed(lngColumns(lngLoop)))) ^ 2
Next
Loop
Close #intFN
strFilename = Dir()
Loop
Debug.Print lngCount
For lngLoop = 1 To 4
Debug.Print dblSums(lngColumns(lngLoop)), dblAvgs(lngColumns(lngLoop)), dblVariances(lngColumns(lngLoop)), Sqr(dblVariances(lngColumns(lngLoop)))
Next
End Sub
|