Thanks Jon, works as expected; was wondering why extra variables were still required...
Nice and clean now + something new in my VB toolbox 🙂
Cheers,
Announcement
Collapse
No announcement yet.
Cleaner version of script
Collapse
X
-
Guest 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 repliedOriginally posted by jon00 View PostYou 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)
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:
-
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:
-
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:
-
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:
-
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"Tags: None
Leave a comment: