Originally posted by ajachierno
View Post
Announcement
Collapse
No announcement yet.
Case statment not working?!?!?
Collapse
X
-
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:
-
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:
-
Originally posted by sparkman View Post
How are you calling the script from HS Touch?
That last one wouldnt run at all just an error.
Leave a comment:
-
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:
-
Originally posted by ajachierno View PostUgh 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:
-
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.
Leave a comment:
-
Originally posted by sparkman View PostIt's your X=parm(0) statement that is messing it up as that truncates it to just "K".
Leave a comment:
-
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:
-
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:
-
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:
-
It's your X=parm(0) statement that is messing it up as that truncates it to just "K".
Leave a comment:
-
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:
-
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:
Leave a comment: