Announcement

Collapse
No announcement yet.

Help with error - "Object reference not set to an instance of an object. "

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with error - "Object reference not set to an instance of an object. "

    I'm getting this error, but I don't understand where it is coming from...

    Do I need to prefex the Device Name with both FLOOR and ROOM?

    HS documentation doesn't say!

    thx for the help



    Code:
    'VB.Net script exception(0), re-starting: Object reference not set to an instance of an object. 
    
    dim array_windows() as string = {"Laundry Room Window","Kitchen Window South","Kitchen Window North","Main Window North","Main Windows 2","Main Window 3","Main Window South","Dining Window South","Dining Window Middle","Dining Window North","Den Window North","Den Window Left","Den Window Middle","Den Window Right","Office Window","Basement Window South","Basement Window Middle","Basement Window North"}
    dim array_doors() as string = {"Deck Sliding Door","Media Room Patio Door","Patio Sliding Door"}
    dim array_locks() as string = {"Mudroom Door Lock","Foyer Door Lock"}
    dim windows_count as integer = 0
    dim doors_count as integer = 0
    dim door_name as String = ""
    dim dstr as string = ""
    dim window_name as string = ""
    dim wstr as string = ""
     
    sub windows(ByVal Parms as Object)
    Try
    windows_count = 0
    window_name = ""
    wstr = ""
     for each devw as string in array_windows
        if hs.DeviceValueByName(devw) = 255 or hs.DeviceValueByName(devw) = 100 then
            windows_count = windows_count + 1
            window_name = devw
            wstr = wstr & window_name & " Opened" & "<br>"
        Else If hs.DeviceValueByName(devw) = 0 then 'No windows open
        end if
    next
        If windows_count > 0 then 
            hs.SetDeviceValueByRef(439,100,true)
            hs.SetDeviceString(439, wstr,true)
        Else
            hs.SetDeviceValueByRef(439,0,true)
            hs.SetDeviceString(439, "All Windows Closed",true)
        End If
        
        hs.writelog("Array", "Window Count: " & windows_count)
     Catch ex As Exception
    hs.WriteLog ("Array", "Error: " & ex.Message)
    End Try
    End Sub
     sub doors(ByVal Parms as Object)
    Try
    doors_count = 0
    door_name = ""
    dstr = ""
    for each devd as string in array_doors
        if hs.DeviceValueByName(devd) = 255 or hs.DeviceValueByName(devd) = 100 or hs.DeviceValueByName(devd) = 22 then
            doors_count = doors_count + 1
            door_name = devd
            dstr = dstr & door_name & " Opened" & "<br>"
        Else If hs.DeviceValueByName(devd) = 0 then 'No doors open
        end if
    next
        If doors_count > 0 then 
            hs.SetDeviceValueByRef(438,100,true) 'was 170
            hs.SetDeviceString(438, dstr,true) 'was 170
        Else
            hs.SetDeviceValueByRef(438,0,true)
            hs.SetDeviceString(438, "All Doors Closed",true)
        End If
    Catch ex As Exception
    hs.WriteLog ("Array", "Error: " & ex.Message)
    End Try
    End Sub

  • #2
    You might want to download Tenholde's tenscripting tool. That will help you debug your script in a "proper" development environment. This way you can step through your code and easily pinpoint where you are going wrong.
    Nicolai L

    Comment

    Working...
    X