In post#10, we have tested the Checkboxes for packages, and in post#12, Checkboxes for protocols are tested. As I said before, there are 3 layers to organize the workstation measurements. The first layer is the package, and the second layer is the protocol. Today, we will use TestPartner test the Checkboxes for the third layer, i.e., the measurement.
From the script below, you can practice the following things again, which you have learned from previous posts:
1, Post#9: Get data from Excel
2, Post#11: Test Windows TreeView with Checkbox
3, Post#13: Error handling in VBA
For number 3, you will also see an improvement compare to the script in post #12: A better place to put the “On Error GoTo 0″ to capture all the errors except the scroll-bar error.
'Testing condition: After clean install.
'Check all the measurements from all the measurement packages - protocols are enabled in the Preference panel - Measurement tab
'$TPinclude "Declaration_GlobalConstants"
Sub Main()
Dim RowCount As Integer
Dim ColumnCount As Integer
Dim SheetData() As String 'Dynamic array
'Use Shared Modules "Function_ExcelSheetRowCount" and "Function_ExcelSheetColumnCount"
'to get how many rows and columns in the Measurement sheet of "MeasurementTab.xlsx"
RowCount = Function_ExcelSheetRowCount.ExcelSheetRowCount(ExcelFilePath_MeasurementTab, "Measurement")
ColumnCount = Function_ExcelSheetColumnCount.ExcelSheetColumnCount(ExcelFilePath_MeasurementTab, "Measurement")
'Array is sized dynamically
ReDim SheetData(RowCount, ColumnCount) As String
'Use Shared Module "Function_GetExcelSheetData" to store data from the Measurement sheet of "MeasurementTab.xlsx" in the array
SheetData() = Function_GetExcelSheetData.GetExcelSheetData(ExcelFilePath_MeasurementTab, "Measurement")
'Open the workstation
ProgramManagerWindow("Application=EXPLORER.EXE Caption='Program Manager'").Attach
ListView("Index=1").Select "the workstation", tpMouseDoubleClick
'In the workstation, open Preference panel, then open the Measurement tab
Window("Application=VSIAPP.EXE Caption=the workstation").Attach
Button("Caption=Prefs").Click
TabControl("Parent.Caption=Preferences").Select " Measurement "
'Select different Packages from the ComboBox, expand Protocol nodes, and check their measurements are enabled
For i = 1 To ColumnCount
For j = 1 To RowCount
If j = 1 Then 'First row in the Measurement sheet is package name
ComboBox("Parent.Caption=Preferences").Select SheetData(1, i) 'Select the package
Dim Package As String
Package = SheetData(1, i)
ElseIf j = 2 Then 'Second row in the Measurement sheet is protocol name
Dim ProtocolPath As String
ProtocolPath = "\Measurements\" & SheetData(j, i)
'Report error if the protocol name read from Excel sheet
'does NOT match the protocol name displayed in the workstation
On Error GoTo 0 'Disables error handling in the current procedure
TreeView("Parent.Caption=Preferences").SelectItem ProtocolPath, , tpTreeButton 'Expand Protocol nodes
Else
'If the Excel cell is not empty, check all the CheckBoxes beside measurement nodes
If SheetData(j, i) <> "" Then
Dim MeasurementPath As String
MeasurementPath = ProtocolPath & "\" & SheetData(j, i)
'Report error if the measurement name read from Excel sheet
'does NOT match the measurement name displayed in the workstation
'On Error GoTo 0 'Disables error handling in the current procedure
TreeView("Parent.Caption=Preferences").SelectItem (MeasurementPath)
'Store the mouse y position after "SelectItem", which is always
'in the middle of the first charactor of the measurement name
Dim y As Integer
y = TreeView("Parent.Caption=Preferences").MouseY
'Handle the situation when the measurement name is longer than the width of the treeview window
On Error Resume Next 'Handle the situation when there is no scroll bar
TreeView("Parent.Caption=Preferences").Scroll 0, tpScrollHorizontal
On Error GoTo 0 'This is a better place
'Search if the CheckBoxInTreeView.bmp (13*13 pixels) exists or not
'Write the results to result summary.
If TreeView("Parent.Caption=Preferences").BitmapExists("CheckBoxInTreeView", 58, y - 8, 17, 17) Then
UserCheck "CheckBoxInTreeView", True, "The " & Package & MeasurementPath & " CheckBox is checked"
Else
UserCheck "CheckBoxInTreeView", False, "The " & Package & MeasurementPath & " CheckBox is NOT checked"
End If
End If
End If
Next
Next
'Close application to reset its original state
Window.Close
End Sub







