Announcement

Collapse
No announcement yet.

Cleaner version of script

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

    Cleaner version of script

    Wrote this small script to optimize a device string for Hstouch display;
    still learning to script VB so pretty sure there is a cleaner way to get the same result, open to ideas to optimize this:

    Sub Main(ByVal Parms as String)

    Code:
    Dim X As String = hs.DeviceString(2405)
    Dim Y As String
    Dim Z As String
    Dim A As String
    
    Y = Replace(X, "km/h", "")
    Z = Replace(Y, "rafale", "-")
    A = Replace(Z, " ", "")
    hs.SetDeviceString(8622, A, true)
    
    End Sub

    "O 32 km/h rafale 46 km/h"
    becomes
    "O32-46"

    #2
    You can shorten it to:

    Code:
            Dim X As String = hs.DeviceString(2405).Replace(X, "km/h", "").Replace(Y, "rafale", "-").Replace(Z, " ", "")
            hs.SetDeviceString(8622, X, True)
    Jon

    Comment


      #3
      I may be naive, but since a vb.net script is compiled before running, what effect does the structure of the text file have on the efficiency of the output executable file?

      It has always been my goal to make the input file as readable as possible. I've never worried about making it compact. Is there a better way?
      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


        #4
        For your first question, dealing with a basic HomeSeer script, probably nothing.

        With more complex examples which take time to execute, the choice of routine/methods can impact on the overall performance of the script.

        Here is a discussion regarding case vs if then statements: https://stackoverflow.com/questions/...itch-case-in-c
        Jon

        Comment


          #5
          Originally posted by jon00 View Post
          You can shorten it to:

          Code:
           Dim X As String = hs.DeviceString(2405).Replace(X, "km/h", "").Replace(Y, "rafale", "-").Replace(Z, " ", "")
          hs.SetDeviceString(8622, X, True)
          Thanks Jon, my revised script now looks like this:


          Code:
          Sub Main(ByVal Parms as String)
          
          Dim Y As String
          Dim Z As String
          Dim X As String = hs.DeviceString(2405).Replace(X, "km/h", "").Replace(Y, "rafale", "-").Replace(Z, " ", "")
          
          hs.SetDeviceString(8622, X, True)
          
          End Sub


          but returns the following


          :Exception has been thrown by the target of an invocation.Overload resolution failed because no accessible 'Replace' accepts this number of arguments.

          Comment


            #6
            Not awake this morning.

            It should have shown:

            Code:
             Dim X As String = hs.DeviceString(2405).Replace("km/h", "").Replace("rafale", "-").Replace(" ", "")  
            hs.SetDeviceString(8622, X, True)
            Jon

            Comment


              #7
              Thanks Jon, works as expected; was wondering why extra variables were still required...
              Nice and clean now + something new in my VB toolbox 🙂
              Cheers,

              Comment

              Working...
              X