Announcement

Collapse
No announcement yet.

Script not compiling in HS. Ran fin in tenScripting

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

    Script not compiling in HS. Ran fin in tenScripting

    I'm stumped and need help finding the issue with this script! This is my first semi complex script, so it's entirely possible I made a mistake or added a function mono doesn't support. This script was made and tested in tenScripting (Visual Studio 2013) and ran fine in the developer but when copied to HS the following logs are received.

    My system is a HomeTroller SEL on 3.0.0.313.

    Are there any commands not recognized by Mono? Odd that it ran fine in tenScripting but fails when moved to HS.

    Code:
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: 'End Namespace' must be preceded by a matching 'Namespace'.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Identifier expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Expected 'End'.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Expected 'End'.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Expected 'End'.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: CHANGEME
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Expected 'End'.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: End of statement expected.
    Apr-03 23:42:13	 	Error	Compiling script /usr/local/HomeSeer/scripts/MatchDevice.vb: Expected ')'.
    Below is the script.

    Code:
    Sub Main(ByVal parm As String)
            'Description: -----------------------------------------------------------
            'This script is ran by an event and evaluates devices (parameter 3 - N) and tallies the 
            'number of devices that contain one of the search strings (parameter 1) and are 'on' 
            'and adds the tally and list of names names as value and string to a virtual device 
            '(parameter 0). This virtual devices can then be used in HSTouch to display the on 
            'status for several devices at once. For example, this script can show the status of all lights 
            'Parameters: ------------------------------------------------------------
            'all parameters are separated by | (pipe) except the second parameter (1)
            'first parameter (0) is the virtual device to set value and string
            'second parameter (1) is the search strings separated by ?. Example light?fan
            'third parameter (2) is True to enable debug or False to disable
            'remaining parameters (3 - N) are the devices to evaluate
            'Example parameter: 376|light?ceiling?fan|False|170|164|167|44
    
            Dim logName As String = "HS3 MatchDevice"
            Dim matchCount As Integer = 0
            Dim matchDeviceNames As String = "None"
    
            If parm.Length > 0 Then
                Dim parmArray() As String = parm.ToString.Split(New Char() {"|"c})
                Dim StatusDevice As Integer = CType(parmArray(0), Integer)
                Dim matchText As String = parmArray(1)
                Dim matchTextArray() As String = matchText.ToString.Split(New Char() {"?"c})
                Dim Debug As Boolean = CType(parmArray(2), Boolean)
    
                If Debug Then
                    'Debug print raw parameters in HS log
                    hs.WriteLog(logName, "Raw Parameter: " + parm)
                    'Debug print number of characters in parameter in HS log
                    hs.WriteLog(logName, "Characters in Parameter: " + CType(parm.Length, String))
                    hs.WriteLog(logName, "---------------------------------")
                    'Debug print each parm to HS log
                    For index As Integer = 0 To parmArray.GetUpperBound(0)
                        hs.WriteLog(logName, "Parm" + CType(index, String) + ": " + parmArray(index))
                    Next
                    hs.WriteLog(logName, "---------------------------------")
                    'Debug print device that will receive the value and string to HS log
                    hs.WriteLog(logName, "Status Device: " + parmArray(0))
                    'Debug print match strings in HS log
                    For j As Integer = 0 To matchTextArray.GetUpperBound(0)
                        hs.WriteLog(logName, "Match String: " + CType(j, String) + ": " + matchTextArray(j))
                    Next
                    For index As Integer = 3 To parmArray.GetUpperBound(0)
                        hs.WriteLog(logName, "Device: " + CType(index - 3, String) + ": " + parmArray(index))
                    Next
                    hs.WriteLog(logName, "---------------------------------")
                End If
    
                Try
                    'search for string in names of passed in devices
                    For index As Integer = 3 To parmArray.GetUpperBound(0)
                        'get name of device
                        Dim dv As Scheduler.Classes.DeviceClass
                        dv = CType(hs.GetDeviceByRef(CInt(parmArray(index))), Scheduler.Classes.DeviceClass)
                        Dim strDevName As String = dv.Name(hs)
                        Dim strDevLoc1 As String = dv.Location(hs)
    
                        'do case insensitive search for matchTextArray
                        If matchTextArray.Any(Function(b) strDevName.IndexOf(b, StringComparison.CurrentCultureIgnoreCase) >= 0) Then
    
                            'is device on?
                            If hs.DeviceValueEx(CInt(parmArray(index))) > 0 Then
                                matchCount = matchCount + 1
                                If Debug Then hs.WriteLog(logName, matchCount.ToString)
                                'first match singular
                                If matchCount = 1 Then
                                    matchDeviceNames = strDevLoc1 + " " + strDevName
                                    'last match
                                ElseIf matchCount = parmArray.GetUpperBound(0) Then
                                    matchDeviceNames = matchDeviceNames + ", " + strDevLoc1 + " " + strDevName + "."
                                    'all other matches
                                Else
                                    matchDeviceNames = matchDeviceNames + ", " + strDevLoc1 + " " + strDevName
                                End If
                            End If
                        End If
                    Next
                    'output number of matches and names to HS log
                    If Debug Then
                        If Debug Then hs.WriteLog(logName, "Number of " + matchText + "s On: " + matchCount.ToString + " - Names: " + matchDeviceNames)
                    End If
                    'set value and string of 'Lights On' device
                    hs.SetDeviceValueByRef(StatusDevice, matchCount, True)
                    hs.SetDeviceString(StatusDevice, matchDeviceNames, False)
    
                Catch ex As Exception
                    hs.WriteLog(logName, ex.Message)
                End Try
            Else
                hs.WriteLog(logName, "-------------------------------------------------------")
                hs.WriteLog(logName, "Example parameter: 376|light?ceiling?fan|False|170|164|167|44")
                hs.WriteLog(logName, "remaining parameters (3 - N) are the devices to evaluate")
                hs.WriteLog(logName, "third parameter (2) is True to enable debug or False to disable")
                hs.WriteLog(logName, "second parameter (1) is the search strings separated by ?. Example light?fan")
                hs.WriteLog(logName, "first parameter (0) is the virtual device to set value and string")
                hs.WriteLog(logName, "all parameters are separated by | (pipe) except the second parameter (1)")
                hs.WriteLog(logName, "At least the first four parameters (0-3) are required")
                hs.WriteLog(logName, "-------------------------------------------------------")
                hs.WriteLog(logName, "No Parameters Specified.")
                hs.WriteLog(logName, "-------------------------------------------------------")
            End If
    
        End Sub
    Last edited by mwolter; April 11, 2017, 09:54 AM.

    #2
    Did you leave a Namespace entry in your script when you copied it across? If so, delete it.
    Jon

    Comment


      #3
      Hello Jon00,
      I don't believe so. No Imports statement at the top of the script. The script posted is exactly the same as it is in the scripts folder.

      Checked and my SEL is running Mono 3.2.8 and is from Feb 2014. It's the version my SEL came with from HS. Do you think this is too old?

      Comment


        #4
        No I don't think it is anything to do with your Mono version. The script looks fine to me and does not error when I pasted it into VS.

        Perhaps you have a corrupt script file. How did you copy it to the SEL?
        Jon

        Comment


          #5
          Tried pasting through the event, creating a new file through webmin and exporting from tenScript. They all have the same error.

          Comment


            #6
            So if you delete all the code apart from Sub Main(ByVal parm As String) and End Sub does it run OK?
            Jon

            Comment


              #7
              Yes, I actually deleted most of the script (everything between "If parm.Length > 0 Then" and its corresponding End If) and the script ran fine. Didn't do anything but there weren't any errors either.

              Comment


                #8
                All I can suggest is that you add code where you can or add remarks until you find the offending line.
                Jon

                Comment


                  #9
                  Looks like it has an issue with this line.

                  Code:
                  If matchTextArray.Any(Function(b) strDevName.IndexOf(b, StringComparison.CurrentCultureIgnoreCase) >= 0) Then
                  Don't think it likes the function. Any other way to search a string for a list of strings?

                  Comment


                    #10
                    Well this really sucks. Wasted A LOT of time. Found this info here. Posting it in this forum so it's easier to find.

                    The VB compiler in Mono only supports VB8 (that's the version that came with VS 2005), which is why lambdas don't compile.
                    Guess this is another reason to learn C#. Are there still reports of memory leaks in C# or has this been resolved?

                    Comment


                      #11
                      Originally posted by mwolter View Post
                      Well this really sucks. Wasted A LOT of time. Found this info here. Posting it in this forum so it's easier to find.



                      Guess this is another reason to learn C#. Are there still reports of memory leaks in C# or has this been resolved?

                      Thanks for this post - it is a very helpful reference.

                      FYI...in regards to memory leaks with C# scripts - as of .312 release, the memory leaks (per the release notes) have been resolved. I have not had a chance to test as of yet, but the release notes reference can be found here

                      Comment


                        #12
                        One more question for you guys. What is the recommended development environment? I'm using tenScrioting (visual studio 2013) and it is quite easy to make scripts on the IDE but they don't run on the homeseer server. Quite often there is a dependency missing or version incompatibility and it takes quite a long time to sort it out. Is there a trick or a different IDE that I should be using. There has to be something better than just developing the scrip then hoping it will work.

                        I'm on a HomeTroller SEL WITH 3.00.312 and mono 3.28.

                        Comment


                          #13
                          In case anyone is interested, here is the final code that works on a SEL with Mono 3.28. Had to reconfigure quite a few things but it appears to work fine.

                          Tried to make it beginner friendly as it has quite a few comments. Might help beginners (like me, lol) save some time.

                          Note to beginners, please be aware that tenScripting's target framework is .net 4.0 which is for VB10. Mono 3.28 only supports .net framework 2.0 (VB8). This causes confusion as many of the functions will run fine in tenScripting but not on your HomeTroller.

                          Code:
                          Imports System.Convert
                              Public Sub Main(ByVal parm As String)
                          
                                  'Description: -----------------------------------------------------------
                                  'This script is ran by an event and evaluates devices (parameter 9 - N) and tallies the 
                                  'number of devices that contain one of the search strings (parameter 1) and are 'on' 
                                  'and adds the tally and list of names names as value and string to a virtual device 
                                  '(parameter 0). This virtual devices can then be used in HSTouch to display the on 
                                  'status for several devices at once. For example, this script can show the status of all lights 
                                  'Parameters: ------------------------------------------------------------
                                  'all parameters are separated by | (pipe) except the second parameter (1)
                                  'first parameter (0) is the virtual device reference to set value and string
                                  'second parameter (1) is the search strings separated by ?. Example: light?fan
                                  'third parameter (2) is True to enable debug or False to disable. True | False
                                  'fourth parameter (3) is the state to include in the virtual device string. Example: on, open, occupied
                                  'fifth parameter (4) show device's Location 2. True | False
                                  'sixth parameter (5) show device's Location 1. True | False
                                  'seventh parameter (6) show device's Name. True | False
                                  'eighth parameter (7) string to pass if no matched devices are on. (blank) | No lights are on.
                                  'nineth parameter (8) include search string in virtual device string? True | False
                                  'remaining parameters (9 - N) are the device references to evaluate
                                  'Example parameter: 376|light?ceiling?fan|False|on|False|True|True|No lights are on.|True|170|164|167|44
                          
                                  Dim logName As String = "HS3 DeviceString"
                                  Dim matchCount As Integer = 0
                                  Dim matchDeviceNames As String = Nothing
                                  Dim matchDeviceNamesArray() As String = {""}
                          
                                  If parm.Length > 0 Then
                                      Dim parmArray() As String = parm.ToString.Split(New Char() {"|"c})
                                      Dim OnDevice As Integer = CType(parmArray(0), Integer)
                                      Dim matchText As String = parmArray(1)
                                      Dim matchTextArray() As String = matchText.ToString.Split(New Char() {"?"c})
                                      Dim Debug As Boolean = CType(parmArray(2), Boolean)
                                      Dim state As String = parmArray(3)
                                      Dim ShowLoc2 As Boolean = CType(parmArray(4), Boolean)
                                      Dim ShowLoc1 As Boolean = CType(parmArray(5), Boolean)
                                      Dim ShowDevName As Boolean = CType(parmArray(6), Boolean)
                                      Dim OffString As String = parmArray(7)
                                      Dim SearchStringDo As Boolean = CType(parmArray(8), Boolean)
                                      Dim SearchStringTxt As String
                          
                                      If Debug Then
                                          'Debug print raw parameters in HS log
                                          hs.WriteLog(logName, "Raw Parameter: " + parm)
                                          'Debug print number of characters in parameter in HS log
                                          hs.WriteLog(logName, "Characters in Parameter: " + CType(parm.Length, String))
                                          hs.WriteLog(logName, "---------------------------------")
                                          'Debug print each parm to HS log
                                          For index As Integer = 0 To parmArray.GetUpperBound(0)
                                              hs.WriteLog(logName, "Parm" + CType(index, String) + ": " + parmArray(index))
                                          Next
                                          hs.WriteLog(logName, "---------------------------------")
                                          'Debug print device that will receive the value and string to HS log
                                          hs.WriteLog(logName, "Status Device: " + parmArray(0))
                                          'Debug print match strings in HS log
                                          For j As Integer = 0 To matchTextArray.GetUpperBound(0)
                                              hs.WriteLog(logName, "Match String: " + CType(j, String) + ": " + matchTextArray(j))
                                          Next
                                          hs.WriteLog(logName, "Device state string status: " + parmArray(3))
                                          For index As Integer = 9 To parmArray.GetUpperBound(0)
                                              hs.WriteLog(logName, "Device: " + CType(index - 9, String) + ": " + parmArray(index))
                                          Next
                                          hs.WriteLog(logName, "---------------------------------")
                                      End If
                          
                                      Try
                                          'search for string in names of passed in devices
                          
                          
                                          For index As Integer = 9 To parmArray.GetUpperBound(0)
                                              'get name of device
                                              Dim dv As Scheduler.Classes.DeviceClass
                                              dv = CType(hs.GetDeviceByRef(CInt(parmArray(index))), Scheduler.Classes.DeviceClass)
                                              Dim strDevName As String = dv.Name(hs)
                                              Dim strDevLoc1 As String = dv.Location(hs)
                                              Dim strDevLoc2 As String = dv.Location2(hs)
                          
                                              If Debug Then hs.WriteLog(logName, "Found match name: " & strDevLoc1 + " " + strDevName + " Testing if " + state + ".")
                          
                                              For j As Integer = 0 To matchTextArray.GetUpperBound(0)
                          
                                                  'do case insensitive search for string
                                                  If strDevName.IndexOf(matchTextArray(j), 0, StringComparison.CurrentCultureIgnoreCase) > -1 Then
                                                      'is device on?
                                                      If hs.DeviceValueEx(CInt(parmArray(index))) > 0 Then
                                                          matchCount = matchCount + 1
                                                          'add device location and name as an additional entry on the list 
                          
                                                          'if it is not the first device found
                                                          If matchDeviceNamesArray(matchDeviceNamesArray.GetUpperBound(0)) IsNot "" Then
                                                              'add new row to array
                                                              ReDim Preserve matchDeviceNamesArray(matchDeviceNamesArray.GetUpperBound(0) + 1)
                                                          End If
                          
                                                          'construct device name
                                                          If ShowLoc2 Then
                                                              If ShowLoc1 Then
                                                                  If ShowDevName Then         'ShowLoc2 True and ShowLoc1 True and ShowDevName True
                                                                      matchDeviceNamesArray(matchDeviceNamesArray.GetUpperBound(0)) = strDevLoc2 + " " + strDevLoc1 + " " + strDevName
                                                                  Else                        'ShowLoc2 True and ShowLoc1 True and ShowDevName False
                                                                      matchDeviceNamesArray(matchDeviceNamesArray.GetUpperBound(0)) = strDevLoc2 + " " + strDevLoc1
                                                                  End If
                                                              Else
                                                                  If ShowDevName Then         'ShowLoc2 True and ShowLoc1 False and ShowDevName True
                                                                      matchDeviceNamesArray(matchDeviceNamesArray.GetUpperBound(0)) = strDevLoc2 + strDevName
                                                                  Else                        'ShowLoc2 True and ShowLoc1 False and ShowDevName False
                                                                      matchDeviceNamesArray(matchDeviceNamesArray.GetUpperBound(0)) = strDevLoc2
                                                                  End If
                                                              End If
                                                          Else
                                                              If ShowLoc1 Then
                                                                  If ShowDevName Then         'ShowLoc2 False and ShowLoc1 True and ShowDevName True
                                                                      matchDeviceNamesArray(matchDeviceNamesArray.GetUpperBound(0)) = strDevLoc1 + " " + strDevName
                                                                  Else                        'ShowLoc2 False and ShowLoc1 True and ShowDevName False
                                                                      matchDeviceNamesArray(matchDeviceNamesArray.GetUpperBound(0)) = strDevLoc1
                                                                  End If
                                                              Else
                                                                  If ShowDevName Then         'ShowLoc2 False and ShowLoc1 False and ShowDevName True
                                                                      matchDeviceNamesArray(matchDeviceNamesArray.GetUpperBound(0)) = strDevName
                                                                  Else                        'ShowLoc2 False and ShowLoc1 False and ShowDevName False
                                                                      matchDeviceNamesArray(matchDeviceNamesArray.GetUpperBound(0)) = "Parameters to show the device's Location2, Location1 and Name are False"
                                                                  End If
                                                              End If
                                                          End If
                          
                          
                                                          If Debug Then
                                                              For k As Integer = 0 To matchDeviceNamesArray.GetUpperBound(0)
                                                                  hs.WriteLog(logName, "Device" + CType(k, String) + " " + state + ": " + matchDeviceNamesArray(k))
                                                              Next
                                                          End If
                          
                                                          'If name is matched, stop searching for additional matches on this device
                                                          Exit For
                                                      End If
                                                  End If
                                              Next
                                          Next
                          
                                          'include search string in virtual device string?
                                          If SearchStringDo Then
                                              If matchTextArray.GetUpperBound(0) = 0 Then                 'one search string
                                                  If matchCount = 1 Then                                  'one device found = singular search string
                                                      SearchStringTxt = matchTextArray(0)
                                                  ElseIf matchCount > 1 Then
                                                      SearchStringTxt = matchTextArray(0) + "s"
                                                  End If
                          
                                              ElseIf matchDeviceNamesArray.GetUpperBound(0) = 1 Then      'two search strings
                                                  If matchCount = 1 Then                                  'one device found = singular search string
                                                      SearchStringTxt = matchTextArray(0) + " or " + matchTextArray(1)
                                                  ElseIf matchCount > 1 Then                              'multiple devices found = plural search string
                                                      SearchStringTxt = matchTextArray(0) + "s or " + matchTextArray(1) + "s"
                                                  End If
                                              Else                                                        'three or more search strings
                                                  'first search string
                                                  If matchCount = 1 Then                                  'one device found = singular search string
                                                      SearchStringTxt = matchTextArray(0)
                                                  ElseIf matchCount > 1 Then                              'multiple devices found = plural search string
                                                      SearchStringTxt = matchTextArray(0) + "s"
                                                  End If
                                                  'second to second to last search string
                                                  For i As Integer = 1 To matchTextArray.GetUpperBound(0) - 1
                                                      If matchCount = 1 Then                              'one device found = singular search string
                                                          SearchStringTxt = SearchStringTxt + ", " + matchTextArray(i)
                                                      ElseIf matchCount > 1 Then                          'multiple devices found = plural search string
                                                          SearchStringTxt = SearchStringTxt + ", " + matchTextArray(i) + "s"
                                                      End If
                                                  Next
                                                  'last search string
                                                  If matchCount = 1 Then                                  'one device found = singular search string
                                                      SearchStringTxt = SearchStringTxt + " or " + matchTextArray(matchTextArray.GetUpperBound(0))
                                                  ElseIf matchCount > 1 Then                              'multiple devices found = plural search string
                                                      SearchStringTxt = SearchStringTxt + " or " + matchTextArray(matchTextArray.GetUpperBound(0)) + "s"
                                                  End If
                                              End If
                                          Else
                                              SearchStringTxt = Nothing
                                              'output number of matches and names to HS log
                                              If Debug Then hs.WriteLog(logName, "Search String: " + SearchStringTxt)
                                          End If
                          
                                          'combine device names in string array matchDeviceNamesArray into one string
                                          If matchDeviceNamesArray(0) IsNot "" Then
                                              If matchDeviceNamesArray.GetUpperBound(0) = 0 Then
                                                  matchDeviceNames = matchDeviceNamesArray(0) + " " + SearchStringTxt + " is " + state + "."
                                              ElseIf matchDeviceNamesArray.GetUpperBound(0) = 1 Then
                                                  matchDeviceNames = matchDeviceNamesArray(0) + " and " + matchDeviceNamesArray(1) + " " + SearchStringTxt + " are " + state + "."
                                              Else
                                                  matchDeviceNames = matchDeviceNamesArray(0)
                                                  For i As Integer = 1 To matchDeviceNamesArray.GetUpperBound(0) - 1
                                                      matchDeviceNames = matchDeviceNames + ", " + matchDeviceNamesArray(i)
                                                  Next
                                                  matchDeviceNames = matchDeviceNames + " and " + matchDeviceNamesArray(matchDeviceNamesArray.GetUpperBound(0)) + " " + SearchStringTxt + " are " + state + "."
                                              End If
                                          Else
                                              matchDeviceNames = OffString
                                              'output number of matches and names to HS log
                                              If Debug Then hs.WriteLog(logName, "Number of " + matchText + "s " + state + ": " + matchCount.ToString + " - Names: " + matchDeviceNames)
                          
                                          End If
                          
                                          'set value and string of 'Lights On' device
                                          hs.SetDeviceValueByRef(OnDevice, matchCount, True)
                                          hs.SetDeviceString(OnDevice, matchDeviceNames, False)
                          
                                      Catch ex As Exception
                                          hs.WriteLog(logName, ex.Message)
                                      End Try
                                  Else
                                      hs.WriteLog(logName, "-------------------------------------------------------")
                                      hs.WriteLog(logName, "Example parameter: 376|light?ceiling?fan|False|on|False|True|True|No lights are on.|170|164|167|44")
                                      hs.WriteLog(logName, "remaining parameters (9 - N) are the devices to evaluate")
                                      hs.WriteLog(logName, "nineth parameter (8) include search string in virtual device string? True | False")
                                      hs.WriteLog(logName, "eighth parameter (7) string to pass if no matched devices are on")
                                      hs.WriteLog(logName, "seventh paramerter (6) show device's Name?")
                                      hs.WriteLog(logName, "sixth paramerter (5) show device's Location 2?")
                                      hs.WriteLog(logName, "fifth paramerter (4) show device's Location 1?")
                                      hs.WriteLog(logName, "fourth parameter (3) is True to enable debug or False to disable")
                                      hs.WriteLog(logName, "third parameter (2) is is the state to include in the virtual device string. Example: On, Open, Occupied")
                                      hs.WriteLog(logName, "second parameter (1) is the search strings separated by ?. Example light?fan")
                                      hs.WriteLog(logName, "first parameter (0) is the virtual device to set value and string")
                                      hs.WriteLog(logName, "all parameters are separated by | (pipe) except the second parameter (1)")
                                      hs.WriteLog(logName, "At least the first ten parameters (0-9) are required")
                                      hs.WriteLog(logName, "-------------------------------------------------------")
                                      hs.WriteLog(logName, "No Parameters Specified.")
                                      hs.WriteLog(logName, "-------------------------------------------------------")
                                  End If
                          
                              End Sub
                          Last edited by mwolter; April 12, 2017, 02:35 PM.

                          Comment


                            #14
                            You can easily change the targeted framework in your tenScripting project to 2.0.

                            tenholde
                            tenholde

                            Comment


                              #15
                              tenholde,
                              I tried changing the targeted framework on the project to 2.0 and it caused the "tenScripting for HS3" window to throw errors.

                              Any assistance you can provide would be greatly appreciated.

                              Comment

                              Working...
                              X