Dim DataTotal As Single
Dim Col_var, TimeReq, LnAvrg, SheetRow, ColRef, RowRef, SheetRef, x_DataVar, LnSkip As Integer
Dim File_1, File_2, File_3, File_4, File_5, File_6, File_7, File_8, File_9, File_10 As String
Private Sub Cmd_1_Click()
File_1 = Application _
.GetOpenFilename("Text Files (*.txt;*.csv), *.txt;*.csv")
Txt_1.Text = File_1
End Sub
Private Sub Cmd_10_Click()
File_10 = Application _
.GetOpenFilename("Text Files (*.txt;*.csv), *.txt;*.csv")
Txt_10.Text = File_10
End Sub
Private Sub Cmd_2_Click()
File_2 = Application _
.GetOpenFilename("Text Files (*.txt;*.csv), *.txt;*.csv")
Txt_2.Text = File_2
End Sub
Private Sub Cmd_3_Click()
File_3 = Application _
.GetOpenFilename("Text Files (*.txt;*.csv), *.txt;*.csv")
Txt_3.Text = File_3
End Sub
Private Sub Cmd_4_Click()
File_4 = Application _
.GetOpenFilename("Text Files (*.txt;*.csv), *.txt;*.csv")
Txt_4.Text = File_4
End Sub
Private Sub Cmd_5_Click()
File_5 = Application _
.GetOpenFilename("Text Files (*.txt;*.csv), *.txt;*.csv")
Txt_5.Text = File_5
End Sub
Private Sub Cmd_6_Click()
File_6 = Application _
.GetOpenFilename("Text Files (*.txt;*.csv), *.txt;*.csv")
Txt_6.Text = File_6
End Sub
Private Sub Cmd_7_Click()
File_7 = Application _
.GetOpenFilename("Text Files (*.txt;*.csv), *.txt;*.csv")
Txt_7.Text = File_7
End Sub
Private Sub Cmd_8_Click()
File_8 = Application _
.GetOpenFilename("Text Files (*.txt;*.csv), *.txt;*.csv")
Txt_8.Text = File_8
End Sub
Private Sub Cmd_9_Click()
File_9 = Application _
.GetOpenFilename("Text Files (*.txt;*.csv), *.txt;*.csv")
Txt_9.Text = File_9
End Sub
Private Sub Cmd_cancel_Click()
Unload Me
End Sub
Private Sub Cmd_ok_Click()
LnAvrg = CInt(Frm_1.Txt_LnNum_1.Value) ' Number of lines to average
x_Dlim = Frm_1.Txt_Dlim.Value ' The delimiter character
LnSkip = Frm_1.Txt_LnSkip ' Number of lines to skip at the beginning
'Processing the first file
If Not Frm_1.Txt_1.Value = "" Then
FileToOpen = Frm_1.Txt_1.Value
SheetRow = RowRef
SheetCol = ColRef
x_DataVar = 1
'Now we get the time for the data set
GoSub GetData
SheetRow = RowRef
SheetCol = ColRef + 1
x_DataVar = 2
'Now we get the data set from the first file
GoSub GetData
End If
'Processing file 2
If Not Frm_1.Txt_2.Value = "" Then
FileToOpen = Frm_1.Txt_2.Value
SheetRow = RowRef
SheetCol = ColRef + 2
x_DataVar = 2
'Now we get the data set from file 2
GoSub GetData
End If
'Processing file 3
If Not Frm_1.Txt_3.Value = "" Then
FileToOpen = Frm_1.Txt_3.Value
SheetRow = RowRef
SheetCol = ColRef + 3
x_DataVar = 2
'Now we get the data set from file 3
GoSub GetData
End If
'Processing file 4
If Not Frm_1.Txt_4.Value = "" Then
FileToOpen = Frm_1.Txt_4.Value
SheetRow = RowRef
SheetCol = ColRef + 4
x_DataVar = 2
'Now we get the data set from file 4
GoSub GetData
End If
'Processing file 5
If Not Frm_1.Txt_5.Value = "" Then
FileToOpen = Frm_1.Txt_5.Value
SheetRow = RowRef
SheetCol = ColRef + 5
x_DataVar = 2
'Now we get the data set from file 5
GoSub GetData
End If
'Processing file 6
If Not Frm_1.Txt_6.Value = "" Then
FileToOpen = Frm_1.Txt_6.Value
SheetRow = RowRef
SheetCol = ColRef + 6
x_DataVar = 2
'Now we get the data set from file 6
GoSub GetData
End If
'Processing file 7
If Not Frm_1.Txt_7.Value = "" Then
FileToOpen = Frm_1.Txt_7.Value
SheetRow = RowRef
SheetCol = ColRef + 7
x_DataVar = 2
'Now we get the data set from file 7
GoSub GetData
End If
'Processing file 8
If Not Frm_1.Txt_8.Value = "" Then
FileToOpen = Frm_1.Txt_8.Value
SheetRow = RowRef
SheetCol = ColRef + 8
x_DataVar = 2
'Now we get the data set from file 8
GoSub GetData
End If
'Processing file 9
If Not Frm_1.Txt_9.Value = "" Then
FileToOpen = Frm_1.Txt_9.Value
SheetRow = RowRef
SheetCol = ColRef + 9
x_DataVar = 2
'Now we get the data set from file 9
GoSub GetData
End If
'Processing file 10
If Not Frm_1.Txt_10.Value = "" Then
FileToOpen = Frm_1.Txt_10.Value
SheetRow = RowRef
SheetCol = ColRef + 10
x_DataVar = 2
'Now we get the data set from file 10
GoSub GetData
End If
Exit Sub
GetData:
i = FreeFile
Open FileToOpen For Binary Access Read As #i
If LOF(i) > 0 Then
'This loop skips a user determin number of headders
If LnSkip > 0 Then
LineCount = 0
Do
Line Input #1, LnSpool
LineCount = LineCount + 1
Loop Until EOF(i) Or LineCount = LnSkip
End If
While Not EOF(i)
DataTotal = 0
LineCount = 0
Do
Line Input #i, SingleLine
x = Split(SingleLine, x_Dlim, , vbTextCompare)
' This nested If statements determin if it is time or data to be used
' When it is time, only the time from the first line is used
' When it is data it summarises the data value for the defined lines to be averaged
If x_DataVar = 1 Then
If LineCount = 0 Then DataTime = x(x_DataVar) 'This aquires the time stamp for the data set
ElseIf x_DataVar > 1 Then DataTotal = DataTotal + CSng(x(x_DataVar)) ' The Csng function is used to ensure the preservation of the decimal number, in this case as single
End If
LineCount = LineCount + 1
Loop Until EOF(i) Or LineCount = LnAvrg
' This With statement writs the read data to the spreadsheet
' using the sheet, column and row reference obtained
With ThisWorkbook.Sheets(SheetRef)
' This If statement determins if it is time or data before writing it to the cells accordingly
If x_DataVar > 1 Then DataAvg = DataTotal / LineCount Else: DataAvg = DataTime
.Cells(SheetRow, SheetCol) = DataAvg
SheetRow = SheetRow + 1
End With
Wend
End If
Close #i
Return
End Sub
Private Sub Cmd_ref_select_Click()
Dim InputCell As Excel.Range
On Error Resume Next
Frm_1.Hide
' Select the reference cell by using the inputbox method
Set InputCell = _
Application.InputBox(Prompt:="Select first input cell", _
Title:="Cell reference", Type:=8)
RowRef = InputCell.Row ' Row reference number for use when writing to the spreadsheet
ColRef = InputCell.Column ' Column reference number for use when writing to the spreadsheet
SheetRef = InputCell.Parent.Name ' Sheet name for writing to the spreadsheet
' Fill the textbox with the address of the selected reference cell
Frm_1.Txt_CellRef.Text = InputCell.Parent.Name & "!" & InputCell.Address
Frm_1.Show
End Sub