Hi clever coders......
Am getting an Error "Object variable or With block variable not set" after modifying my code below to have multiple IF/End If within a for each/next loop. I was expecting this to be possible but perhaps not, or perhaps there's something else am missing.
Any code after the Next is ignored and the error is displayed on the console. Prior to the change I just had one If/Else/End if but couldn't work a way of doing the required check without multiple If checks, hence the change below.
Am getting an Error "Object variable or With block variable not set" after modifying my code below to have multiple IF/End If within a for each/next loop. I was expecting this to be possible but perhaps not, or perhaps there's something else am missing.
Any code after the Next is ignored and the error is displayed on the console. Prior to the change I just had one If/Else/End if but couldn't work a way of doing the required check without multiple If checks, hence the change below.
Code:
dim array_temps() as Integer = {814,804,788,780,516,355,348,341,191,152,136,76,26,19} ' 22/11/18 Removed battery devices from heat demand list as they take longer to wake up and report - they are still used in the trigger though ' 68,160,487,95 ' 5/1 - removed 267 was Keatons ' 6/1 - removed 76 was Family back dim temperature as decimal = 0 dim setpoint as decimal = 0 dim multilevel as decimal = 0 dim temp_name as string = "" dim tempstr as string = "" dim devicename dim TRVtype dim TRVtypetext as string = "" sub Main(ByVal Parms as Object) Try temp_name = "" tempstr = "" for each devt as Integer in array_temps temp_name = devt TRVtype = hs.GetDeviceByRef(devt+2) TRVtypetext = TRVtype.name(hs) if TRVtypetext="Temperature" ' Old type TRV temperature = hs.DeviceValueEx(devt+2) setpoint = hs.DeviceValueEx(devt+5) multilevel = hs.DeviceValueEx(devt+3) devicename=hs.GetDeviceByRef(devt) 'hs.WriteLog ("Info", TRVtypetext ) End If if TRVtypetext="Power Management Notification" ' New type TRV temperature = hs.DeviceValueEx(devt+4) setpoint = hs.DeviceValueEx(devt+7) multilevel = hs.DeviceValueEx(devt+5) devicename=hs.GetDeviceByRef(devt) 'hs.WriteLog ("Info", TRVtypetext ) End If If hs.DeviceString(devt) = "Communication Failure" then tempstr = tempstr & temp_name & " " & " CF" & "<br>" End If if setpoint > temperature then tempstr = tempstr & devicename.name(hs) & " " & multilevel & "% " & setpoint & " SP " & temperature & " C" & "<br>" End If hs.WriteLog ("Array", tempstr) hs.SetDeviceString(373, tempstr,true) next if tempstr = "" then tempstr = "No Demand" hs.WriteLog ("Array", tempstr) hs.SetDeviceString(373, tempstr,true) end if Catch ex As Exception hs.WriteLog ("Array", "Error: " & ex.Message) End Try End Sub
Comment