Announcement

Collapse
No announcement yet.

Cleaner version of script

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

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

    Leave a comment:


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

    Leave a comment:


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

    Leave a comment:


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

    Leave a comment:


  • Uncle Michael
    replied
    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?

    Leave a comment:


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

    Leave a comment:


  • Guest
    Guest started a topic Cleaner version of script

    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"
Working...
X