Skip to content

MiisApp.vb: Build Export Menu

Private Sub BuildMenus(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim i, j As Int16
Dim Menu_MANames As String()
Menu_MANames = getMANames()

<<Code to define other menus>>

Dim exportLogsMenu As New MenuItem(“Export Logs”)
AddHandler exportLogsMenu.Click, AddressOf BuildMenus

For i = 0 To UBound(Menu_MANames)
‘Construct Export Logs menu
Dim exportLogs As String() = getLogs(Menu_MANames(i), “export”)
Dim exportLogsItem As New MenuItem(Menu_MANames(i))
For j = UBound(exportLogs) To 0 Step -1
Dim timeItem As New MenuItem(exportLogs(j))
AddHandler timeItem.Click, AddressOf DisplayLogFile
exportLogsItem.MenuItems.Add(timeItem)
Next
If UBound(exportLogs) >= 0 Then
exportLogsMenu.MenuItems.Add(exportLogsItem)
End If
Next

Dim myMenu As New MainMenu
myMenu.MenuItems.Add(exportLogsMenu)
Add other menus
Menu = myMenu
End Sub

Private Function getMANames() As String()
<<Return an array of MA names you want to include in the menu>>
End Function

Private Function getLogs(ByVal MAName As String, ByVal profile As String) As String()
Dim folderPath = LOG_PATH & MAName
getLogs = System.IO.Directory.GetFiles(folderPath, profile & “2*.xml”)
End Function

Private Sub DisplayLogFile(ByVal sender As System.Object, ByVal e As System.EventArgs)
‘Only works if you allow the menu text to equal the path. A bit ugly but it simplifies the code.
‘If you want pretty names you have to mess around with hash tables – see here
Dim item As New MenuItem
item = sender
System.Diagnostics.Process.Start(item.Text)
End Sub