Announcement

Collapse
No announcement yet.

Case statment not working?!?!?

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

  • sparkman
    replied
    Originally posted by ajachierno View Post

    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.
    Looks like the End Sub was not pasted into my code.

    Leave a comment:


  • joegr
    replied
    Originally posted by sparkman View Post

    Does it pass an array or an object?
    An array, unlike HomeSeer itself.

    Leave a comment:


  • Wadenut
    replied
    That does tell me there are some extraneous characters in your string. HS wouldn't show these in the log if they're HTML tags or otherwise unprintable characters.
    Just out of curiosity, try:

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

    The Length of X reported likely won't match the visible string.

    Leave a comment:


  • ajachierno
    replied
    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

    Leave a comment:


  • ajachierno
    replied
    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.

    Leave a comment:


  • sparkman
    replied
    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)

    Leave a comment:


  • sparkman
    replied
    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?

    Leave a comment:


  • sparkman
    replied
    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?

    Leave a comment:


  • joegr
    replied
    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.

    Leave a comment:


  • ajachierno
    replied
    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.

    Leave a comment:


  • sparkman
    replied
    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)

    Leave a comment:


  • sparkman
    replied
    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

    Leave a comment:


  • sparkman
    replied
    It's your X=parm(0) statement that is messing it up as that truncates it to just "K".

    Leave a comment:


  • sparkman
    replied
    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

    Leave a comment:


  • joegr
    replied
    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 ?

    Leave a comment:

Working...
X