Announcement

Collapse
No announcement yet.

If statement not working

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

    If statement not working

    I'm trying to do something very basic here but unfortunately the IF statement is not working
    In the log I can can see the Alert from the field
    Apr-21 12:53:57 PM mySQL Alert
    If I remove the IF statement, it will update the device fine. I changed value with spaces, without spaces, uppercases and etc. Something very basic that I'm mssing.

    Code:
    \
    Sub Main(ByVal Parms As String)
    
      ' dim Example as String = ParmArray(0).ToLower      'First Parameter: 
        Dim ParmArray() as String
        ParmArray = Parms.ToString.Split(",")
        dim DeviceRefParm as String = ParmArray(0)     
        dim DeviceAlert as String = ParmArray(1)       
        dim DeviceWarning as String = ParmArray(2)     
    
    
    hs.writelog ("mySQL", DeviceWarning)
    
    [B]if DeviceWarning = "Alert" Then
    hs.SetDeviceValueByRef(1077, 100, True) ' Set Virtual Alert if Parameter 2 is set to Alert
    hs.SetDeviceString(1077, "Alert2: Device " & Dev_DeviceName & " is " & " not responding " , True)
    end if[/B]
    
    End Sub
    Attached Files

    #2
    I wonder if there is a non-printing character in your string.
    Len(DeviceWarning) should be 5. Is it?
    Mike____________________________________________________________ __________________
    HS3 Pro Edition 3.0.0.548, NUC i3

    HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

    Comment


      #3
      Originally posted by Uncle Michael View Post
      I wonder if there is a non-printing character in your string.
      Len(DeviceWarning) should be 5. Is it?
      Interesting, it actually shows 6. Thanks to you, I changed the if with " Alert" and is working. Not sure why it is putting a space before the Alert


      Edit: Your suggestion fixed my issue. In the parm I had (Alarm Device, Alarm) that space was the issue. Thanks you!

      Comment


        #4
        I tend to use the Trim function and the Lcase function to ensure case is ignored and any leading or trailing spaces are removed:

        https://docs.microsoft.com/en-us/dot...tframework-4.8
        https://docs.microsoft.com/en-us/dot...tframework-4.8
        HS 4.2.8.0: 2134 Devices 1252 Events
        Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

        Comment


          #5
          you could try this but I dont think it will change anything -
          String.Compare(str1, str2) = 0 have you printed out DeviceWarning and ParmArray(2) using hs.Writelog()? This might give you some direction.

          Comment

          Working...
          X