Announcement

Collapse
No announcement yet.

Case statment not working?!?!?

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

  • Case statment not working?!?!?

    Ok I am stuck on something very simple and can figure out what I am doing wrong. I am passing this a value from HSTouch and it seems to be passing correctly. My write to the log comes out just fine the value passed from HSTouch is exactly as I would expect but no matter what I do the Y value assigned in the Case argument comes out as 999. Basically even though though X is equal to Kitchen which should return 1 it still returns 999. What have I done wrong here?

    Thanks in advance.



    Sub Main(ByVal parm As Object)
    Dim X As string
    Dim Y As Integer

    X = parm(0)
    X = X.Trim

    Select Case X
    Case "Kitchen"
    Y = 1
    Case "Adams Office"
    Y = 430
    Case "Living Room"
    Y = 2
    Case Else
    Y = 999
    End Select


    hs.writelog("Test", "This is parameter X: " & X.ToString)
    hs.writelog("Test", "This is parameter Y: " & Y.ToString)


    End Sub

  • #2
    Are you sure there are no hidden characters in the parameter like an html tag? Try putting some characters around it when you write it to the log and then look at the html source in the log.
    HS 3.0.0.548: 1990 Devices 1172 Events
    Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

    Comment


    • #3
      Originally posted by sparkman View Post
      Are you sure there are no hidden characters in the parameter like an html tag? Try putting some characters around it when you write it to the log and then look at the html source in the log.
      I put a few characters on either side and came out exactly as expected with the proper word in the middle. This is an entry from a drop down box not sure if that matters?

      Comment


      • #4
        What if you make a test event in HomeSeer and call your script with a parameter of "Kitchen". Does it work then?

        If so, then that points to something odd in the way HStouch is passing the string.

        Edit: you'd have to modify it slightly since HStouch passes differently then HS does from an event.

        Have you tried it without the X = X.Trim ?

        Comment


        • #5
          Are you only passing the one parameter? If so, try this:

          Code:
          Sub Main(ByVal X As String)
          Dim Y As Integer
          
          X = X.Trim
          
          Select Case X
          Case "Kitchen"
          Y = 1
          Case "Adams Office"
          Y = 430
          Case "Living Room"
          Y = 2
          Case Else
          Y = 999
          End Select
          
          
          hs.writelog("Test", "This is parameter X: " & X)
          hs.writelog("Test", "This is parameter Y: " & Y.ToString)
          
          
          End Sub
          HS 3.0.0.548: 1990 Devices 1172 Events
          Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

          Comment


          • #6
            It's your X=parm(0) statement that is messing it up as that truncates it to just "K".
            HS 3.0.0.548: 1990 Devices 1172 Events
            Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

            Comment


            • #7
              This works too:

              Code:
              Sub Main(ByVal parm As Object)
              Dim X As String
              Dim Y As Integer
              
              X = parm.ToString
              X = X.Trim
              
              Select Case X
              Case "Kitchen"
              Y = 1
              Case "Adams Office"
              Y = 430
              Case "Living Room"
              Y = 2
              Case Else
              Y = 999
              End Select
              
              
              hs.writelog("Test", "This is parameter X: " & X)
              hs.writelog("Test", "This is parameter Y: " & Y.ToString)
              
              
              End Sub
              HS 3.0.0.548: 1990 Devices 1172 Events
              Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

              Comment


              • #8
                If you are passing more than one parameter, you need a separator character (like a comma or a |), then split on that character which will create an array:

                Code:
                Sub Main(ByVal Parms As object)
                    Dim ParmArray() as String
                    ParmArray = Parms.ToString.Split(",")            
                    Dim X As String = ParmArray(0)
                HS 3.0.0.548: 1990 Devices 1172 Events
                Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

                Comment


                • #9
                  Ugh thanks for the help, but none of those seem to work they all return the following:

                  Jan-09 9:18:12 PM Test This is parameter Y: 999
                  Jan-09 9:18:12 PM Test This is parameter X: System.String[]

                  Are you sure thats the issue because with the original code it was ruturing the value without issue for X it only seemed to not work in the case statement.

                  Comment


                  • #10
                    Originally posted by sparkman View Post
                    It's your X=parm(0) statement that is messing it up as that truncates it to just "K".
                    You would be correct if this was being called from HomeSeer. However, called from HStouch parm(0) is correct. HStouch can pass several separate parameters as different array elements. At least, it's working that way for me.

                    Comment


                    • #11
                      Originally posted by joegr View Post

                      You would be correct if this was being called from HomeSeer. However, called from HStouch parm(0) is correct. HStouch can pass several separate parameters as different array elements. At least, it's working that way for me.
                      Does it pass an array or an object?
                      HS 3.0.0.548: 1990 Devices 1172 Events
                      Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

                      Comment


                      • #12
                        Originally posted by ajachierno View Post
                        Ugh thanks for the help, but none of those seem to work they all return the following:

                        Jan-09 9:18:12 PM Test This is parameter Y: 999
                        Jan-09 9:18:12 PM Test This is parameter X: System.String[]

                        Are you sure thats the issue because with the original code it was ruturing the value without issue for X it only seemed to not work in the case statement.
                        How are you calling the script from HS Touch?
                        HS 3.0.0.548: 1990 Devices 1172 Events
                        Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

                        Comment


                        • #13
                          Does this work:

                          Code:
                          Sub Main(ByVal parm() As String)
                          Dim X As string
                          Dim Y As Integer
                          
                          X = parm(0)
                          X = X.Trim
                          
                          Select Case X
                          Case "Kitchen"
                          Y = 1
                          Case "Adams Office"
                          Y = 430
                          Case "Living Room"
                          Y = 2
                          Case Else
                          Y = 999
                          End Select
                          
                          
                          hs.writelog("Test", "This is parameter X: " & X.ToString)
                          hs.writelog("Test", "This is parameter Y: " & Y.ToString)
                          HS 3.0.0.548: 1990 Devices 1172 Events
                          Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

                          Comment


                          • #14
                            Originally posted by sparkman View Post

                            How are you calling the script from HS Touch?
                            I am using the "HomeSeer: Run a HomeSeer script with values from elements(s)" function

                            That last one wouldnt run at all just an error.

                            Comment


                            • #15
                              I did find a work around for this. the below code works perfect. Since my values are different enough these seems to solve the overall problem.

                              Sub Main(ByVal parm as Object)
                              Dim X As string
                              Dim Y As Integer

                              X = parm(0).ToString
                              X = X.Trim

                              Select Case True
                              Case X.Contains("Kitchen")
                              Y = 1
                              Case X.Contains("Adams Office")
                              Y = 430
                              Case X.Contains("Living Room")
                              Y = 2
                              Case Else
                              Y = 999
                              End Select

                              hs.writelog("Test", "This is parameter X: " & X.ToString)
                              hs.writelog("Test", "This is parameter Y: " & Y.ToString)

                              End Sub

                              Comment

                              Working...
                              X