ListOfDevices Function: Sample Code for Microsoft® Visual Basic for Excel
Sample Code
Private Sub DisplayMessage(ByVal SentText As String)
TextBox.Text = TextBox.Text + SentText + vbCrLf + vbCrLf
End Sub
Private Sub btnListOfDevices_Click()
Dim objtype, filter As String
Dim xlWB As Excel.Workbook
Set xlApp = Excel.Application
' Checks connection and open case
' SimAuto and caseopen are global variables
If Not SimAuto Is Nothing And caseopen Then
objtype = "branch"
filter = ""
output = SimAuto.ListOfDevices(objtype, filter)
If output(0) <> "" Then
DisplayMessage output(0)
Else
DisplayMessage "Succesful List Of Devices"
' Prepares additional worksheet
Set xlWB = xlApp.Workbooks.Add
' Copies list of devices in worksheet
With xlWB
Sheets("sheet1").Activate
Sheets("sheet1").Name = "ListOfDevices"
With Sheets("ListOfDevices")
Dim i, j As Integer
Range(Cells(1, 5), Cells(200, 7)).Clear
Cells(1, 1) = "List of Devices for " + objtype + ":"
Cells(2, 1) = "From Bus Num"
Cells(2, 2) = "To Bus Num"
Cells(2, 3) = "ID"
' Determine number of key fields retrieved
Dim lowkeyf, highkeyf As Integer
lowkeyf = LBound(output(1), 1)
highkeyf = UBound(output(1), 1)
DisplayMessage "Number of Key Fields: " + Str(lowkeyf) + Str(highkeyf)
' Determine number of objects retrieved
Dim lowobj, highobj As Integer
lowobj = LBound(output(1)(lowkeyf), 1)
highobj = UBound(output(1)(lowkeyf), 1)
DisplayMessage "Number of objects: " + Str(lowobj) + Str(highobj)
For i = lowkeyf To highkeyf
For j = lowobj To highobj
Cells(j + 3, i + 1) = output(1)(i)(j)
Next j
Next i
End With
End With
End If
End If
End Sub