Kan jeg komme med et forbedringsforslag? One-line IF er utmerket for kun én linje, men blir veldig uoversiktelig når den skal dekke flere (samt at det teknisk sett krever mer regnekraft, selv om det er ubetydelig nå om dagen).
Jeg hadde mao. skrevet den siste IF-setningen slik:
' If the current ventilator mode is at the same mode/level we want to set then we do not have to do anything
If (ventModeGetCodeArray(valueVentModeGet) = ventilatorSetModeArray(ventilatorSetLevel)) Then
If Debug Then
hs.WriteLog(logName, "ventModeGetCodeArray(valueVentModeGet) = " & ventModeGetCodeArray(valueVentModeGet))
hs.WriteLog(logName, "ventilatorSetModeArray(ventilatorSetLevel) = " & ventilatorSetModeArray(ventilatorSetLevel))
hs.WriteLog(logName, "If (ventModeGetCodeArray(valueVentModeGet) [" & ventModeGetCodeArray(valueVentModeGet) & "] = ventilatorSetModeArray(ventilatorSetLevel)[" & ventilatorSetModeArray(ventilatorSetLevel) & "] ) Then, no changes in ventilatorSetMode")
End If
Else
' Set ventilator device devVentModeSet to index of ventModeSetCodeArray where value is ventilatorSetLevel translated thru ventModeSetCodeArray
If Debug Then
hs.WriteLog(logName, "If Not (ventModeGetCodeArray(valueVentModeGet) [" & ventModeGetCodeArray(valueVentModeGet) & "] = ventilatorSetModeArray(ventilatorSetLevel)[" & ventilatorSetModeArray(ventilatorSetLevel) & "] ) Then, set ventilator to " & ventilatorSetModeArray(ventilatorSetLevel))
hs.WriteLog(logName, "ventilatorSetLevel = " & ventilatorSetLevel)
hs.WriteLog(logName, "ventilatorSetModeArray(ventilatorSetLevel) = " & ventilatorSetModeArray(ventilatorSetLevel))
hs.WriteLog(logName, "before set devVentModeSet to " & Array.IndexOf(ventModeSetCodeArray, ventilatorSetModeArray(ventilatorSetLevel)))
hs.WriteLog(logName, "hs.CAPIControlHandler(hs.CAPIGetSingleControl(" & devVentModeSet & ", True, " & ventilatorSetModeArray(ventilatorSetLevel) & ", False, False))")
End If
hs.CAPIControlHandler(hs.CAPIGetSingleControl(devVentModeSet, True, ventilatorSetModeArray(ventilatorSetLevel), False, False))
hs.WriteLog(logName, "set devVentModeSet to " & Array.IndexOf(ventModeSetCodeArray, ventilatorSetModeArray(ventilatorSetLevel)))
End If
Det samme med linjene over:
If Debug Then
hs.WriteLog(logName, "valueLivingRoom1_T: " & valueLivingRoom1_T)
hs.WriteLog(logName, "valueLivingRoom1_Co2: " & valueLivingRoom1_Co2)
hs.WriteLog(logName, "valueLivingRoom1_RH: " & valueLivingRoom1_RH)
hs.WriteLog(logName, "valueLivingRoom1_AH: " & valueLivingRoom1_AH)
hs.WriteLog(logName, "valueBath1_T: " & valueBath1_T)
hs.WriteLog(logName, "valueBath1_Co2: " & valueBath1_Co2)
hs.WriteLog(logName, "valueBath1_RH: " & valueBath1_RH)
hs.WriteLog(logName, "valueBath1_AH: " & valueBath1_AH)
hs.WriteLog(logName, "humidDeltaBath1: " & humidDeltaBath1)
hs.WriteLog(logName, "Current Ventilator Mode: " & ventModeGetCodeArray(valueVentModeGet))
hs.WriteLog(logName, "co2ThresholdNormal: " & co2ThresholdNormal)
hs.WriteLog(logName, "co2ThresholdHigh: " & co2ThresholdHigh)
hs.WriteLog(logName, "co2ThresholdMax: " & co2ThresholdMax)
End If