Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click
Dim strFileName As String = ""
' Open file dialog to open Cal data excel file
Dim OpenFileDialog1 As New OpenFileDialog()
OpenFileDialog1.Filter = "Excel files (*.xls)|*.xls"
OpenFileDialog1.Title = "Select Excel file to load data from"
' If the user clicks the open file button, load the file
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Try
'Save the file path and name
strFileName = OpenFileDialog1.FileName
Catch ex As Exception
MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
'Load Cell data from opened EXCEL file into cal program variables
'Path and excelFile variables are used for relative addressing the excel template file
Dim path As String = My.Application.Info.DirectoryPath
Dim excelFile As String = IO.Path.Combine(path, strFileName)
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlWorkSheet1 As Microsoft.Office.Interop.Excel.Worksheet
Dim xlWorkSheet2 As Microsoft.Office.Interop.Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
' Open the MAC125 Calibration data template file
xlApp = New Microsoft.Office.Interop.Excel.Application
xlWorkBook = xlApp.Workbooks.Open(excelFile)
xlWorkSheet1 = CType(xlWorkBook.Sheets("sheet1"), Microsoft.Office.Interop.Excel.Worksheet)
xlWorkSheet2 = CType(xlWorkBook.Sheets("sheet2"), Microsoft.Office.Interop.Excel.Worksheet)
' Populate the template file with MAC125 data
pressure = CInt(xlWorkSheet1.Cells(4, 10))
lblRange.Text = CType((xlWorkSheet1.Cells(4, 4)), String)
txtRoom.Text = CType((xlWorkSheet1.Cells(9, 4)), String)
lblPercent3.Text = CType((xlWorkSheet1.Cells(9, 5)), String)
lblPercent4.Text = CType((xlWorkSheet1.Cells(9, 6)), String)
lblPercent5.Text = CType((xlWorkSheet1.Cells(9, 7)), String)
lblPercent6.Text = CType((xlWorkSheet1.Cells(9, 8)), String)
lblPercent7.Text = CType((xlWorkSheet1.Cells(9, 9)), String)
lblPercent8.Text = CType((xlWorkSheet1.Cells(9, 10)), String)
txtWatlow1.Text = CType((xlWorkSheet1.Cells(10, 3)), String)
txtWatlow2.Text = CType((xlWorkSheet1.Cells(10, 4)), String)
txtWatlow3.Text = CType((xlWorkSheet1.Cells(10, 5)), String)
txtWatlow4.Text = CType((xlWorkSheet1.Cells(10, 6)), String)
txtWatlow5.Text = CType((xlWorkSheet1.Cells(10, 7)), String)
txtWatlow6.Text = CType((xlWorkSheet1.Cells(10, 8)), String)
txtWatlow7.Text = CType((xlWorkSheet1.Cells(10, 9)), String)
txtWatlow8.Text = CType((xlWorkSheet1.Cells(10, 10)), String)
txtDisplay1.Text = CType((xlWorkSheet1.Cells(11, 3)), String)
txtDisplay2.Text = CType((xlWorkSheet1.Cells(11, 4)), String)
txtDisplay3.Text = CType((xlWorkSheet1.Cells(11, 5)), String)
txtDisplay4.Text = CType((xlWorkSheet1.Cells(11, 6)), String)
txtDisplay5.Text = CType((xlWorkSheet1.Cells(11, 7)), String)
txtDisplay6.Text = CType((xlWorkSheet1.Cells(11, 8)), String)
txtDisplay7.Text = CType((xlWorkSheet1.Cells(11, 9)), String)
txtDisplay8.Text = CType((xlWorkSheet1.Cells(11, 10)), String)
btnRange0R0.Text = CType((xlWorkSheet1.Cells(14, 3)), String)
btnRange2R0.Text = CType((xlWorkSheet1.Cells(14, 4)), String)
btnRange4R0.Text = CType((xlWorkSheet1.Cells(14, 5)), String)
btnRange6R0.Text = CType((xlWorkSheet1.Cells(14, 6)), String)
btnRange8R0.Text = CType((xlWorkSheet1.Cells(14, 7)), String)
btnRange10R0.Text = CType((xlWorkSheet1.Cells(14, 8)), String)
btnRange12R0.Text = CType((xlWorkSheet1.Cells(14, 9)), String)
btnRange14R0.Text = CType((xlWorkSheet1.Cells(14, 10)), String)
lblEquation.Text = CType((xlWorkSheet1.Cells(15, 1)), String)
btnRange0R1.Text = CType((xlWorkSheet1.Cells(15, 3)), String)
btnRange2R1.Text = CType((xlWorkSheet1.Cells(15, 4)), String)
btnRange4R1.Text = CType((xlWorkSheet1.Cells(15, 5)), String)
btnRange6R1.Text = CType((xlWorkSheet1.Cells(15, 6)), String)
btnRange8R1.Text = CType((xlWorkSheet1.Cells(15, 7)), String)
btnRange10R1.Text = CType((xlWorkSheet1.Cells(15, 8)), String)
btnRange12R1.Text = CType((xlWorkSheet1.Cells(15, 9)), String)
btnRange14R1.Text = CType((xlWorkSheet1.Cells(15, 10)), String)
mac125Voltage = CByte(xlWorkSheet1.Cells(25, 6))
mac125Model = CByte(xlWorkSheet1.Cells(27, 2))
mac125Status = CByte(xlWorkSheet1.Cells(36, 2))
filterBlowBack = CBool(xlWorkSheet1.Cells(21, 8))
caseCool = CBool(xlWorkSheet1.Cells(23, 8))
caseHeater = CBool(xlWorkSheet1.Cells(25, 8))
digitalDisplay = CBool(xlWorkSheet1.Cells(27, 8))
mac125SerialNumber = CType(xlWorkSheet1.Cells(28, 6), String)
mac125HtProbeSerialNumber = CType(xlWorkSheet1.Cells(30, 6), String)
rangeModuleSerialNumber = CType(xlWorkSheet1.Cells(32, 6), String)
rmaNumber = CType(xlWorkSheet1.Cells(34, 6), String)
purchaseOrderNumber = CType(xlWorkSheet1.Cells(36, 6), String)
dateTested = CType(xlWorkSheet1.Cells(33, 10), String)
xlWorkSheet1.Cells(36, 10) = testedBy = CType(xlWorkSheet1.Cells(36, 10), String)
xlWorkBook.Close()
xlApp.Quit()
xlWorkBook = Nothing
xlWorkSheet1 = Nothing
xlWorkSheet2 = Nothing
End Sub