Sub Process_Globals
Private TableDevices As TableView
Private MyDevices As List 'List of Devices
Type Device (Zone As String, Name As String, DevType As String, Status As Boolean, _
Temperature As Double, Humidity As Double)
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout") 'Load the layout file
MainForm.Show
MyDevices.Initialize
RefreshData
End Sub
Sub RefreshData ()
Wait For (GetDevicesInfo) Complete (Result As Int) 'Get Devices Info and wait for completion
LoadTable
End Sub
Sub GetDevicesInfo ()
'Get data from the REST API webservice
Do While (data > 0)
'Add this device to the list
Dim thisDevice As Device = CreateDevice(zoneID, zoneName, serialNo, deviceType, conValue, 0, 0, 0, "")
MyDevices.Add(thisDevice)
Loop
End Sub
'Create a Device object
Public Sub CreateDevice (Zone As String, SerialNo As String, DevType As String, Status As Boolean, Temperature As Double, Humidity As Double) As Device
Dim dev As Device
dev.Initialize
dev.Zone = Zone
dev.SerialNo = SerialNo
dev.DevType = DevType
dev.Status = Status
dev.Temperature = Temperature
dev.Humidity = Humidity
Return dev
End Sub
'Load values into the table
Sub LoadTable ()
Dim temp As String
Dim humid As String
'Clear the table if data exists
TableDevices.Items.Clear
'Load values
For Each devs As Device In MyDevices
If (devs.Status) Then
temp = NumberFormat2(devs.Temperature, 1, 2, 2, False) & "°C "
humid = NumberFormat2(devs.Humidity, 1, 1, 1, False) & "% "
Else
temp = "---"
humid = "---"
End If
Dim row() As Object = Array (devs.Zone, devs.SerialNo, devs.DevType, devs.Status, temp, humid)
TableDevices.Items.Add(row)
Next
End Sub