Announcement

Collapse
No announcement yet.

Immediate Script Syntax Problem

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

    Immediate Script Syntax Problem

    Can someone tell me what is wrong with this in the Immediate Command window...

    Code:
    [FONT=Courier New]&INTR=HS.PING(8.8.8.8);HS.WRITELOG("Internet","STATUS="& INTR)[/FONT]
    I get the following error:
    Running script(1) &INTR()=HS.PING(8.8.8.8), init error: Expected ')'
    I get this even when I delete everything from the semicolon to the end, in other words, the error has to do with:

    &INTR=HS.PING(8.8.8.8)

    Forgive my ignorance. I'm trying to get back into scripting after about 10 years' absence.


    Jim Speiser
    38-year veteran of Home Automation
    Still don't know squat

    #2
    I'm not sure you can manipulate a return variable in an immediate script statement, because you need to declare the variable. You will probably have to create a short script and run it explicitly. (That's how I do it.)
    You could try to add Dim INTR As Integer; between the & and the assignment statement to see what happens.

    Code:
    Public Sub Main(ByVal Parms As Object)
    
    Dim Google As String = "8.8.8.8"
    Dim intR As Integer
    
    intR = hs.Ping(Google)
    
    If intR = 0 Then
    'hs.WriteLog ("Internet", "OK")
    hs.SetDeviceValueByRef(1657, 0, True)
    Else
    hs.WriteLog ("Internet", "??")
    hs.SetDeviceValueByRef(1657, 100, True)
    End If
    
    End Sub
    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
      Looking in the help file there is this:

      In the Advanced section of the Run Script action, you can add a single script statement. This allows you to execute script commands without creating a file. Statements are preceded with an ampersand (&) so HomeSeer knows to treat it as a statement. For example, the following if then else logic could be typed into the "OR Script Statement" field of the Run Script action:

      For VBScripts and VB.Net scripting:

      &if hs.ison(1234) then hs.SetDeviceValue 1234,0 Else hs.SetDeviceValue 1234, 100

      or

      &hs.SetDeviceString 5678,"Garage Open",false

      Multiple statements may be added to the "OR Script Statement" field. Separate each statement with a colon.
      You could try separating with a : instead of a semicolon.

      Comment


        #4
        Originally posted by AllHailJ View Post
        Looking in the help file there is this:

        You could try separating with a : instead of a semicolon.
        What help file is this from??

        I see no 'Advanced' section for the 'Run Script' action (HS3 or HS4).

        I tried a colon separator - yields a syntax error.

        Code:
         [TABLE="class: log_table_row, width: 970"]
        [TR]
        [TD="class: LogDateShort LogDateTime1, bgcolor: #ffffff, align: left"][SIZE=13px][FONT=Courier-New][COLOR=#FF0000]Nov-14 16:27:27[/COLOR][/FONT][/SIZE][/TD]
         			[TD="class: LogPri1, bgcolor: #ffffff, align: left"] [/TD]
         			[TD="class: LogType1, bgcolor: #ffffff, colspan: 3, align: left"][SIZE=12px][FONT=Courier-New][COLOR=#FF0000]Error[/COLOR][/FONT][/SIZE][/TD]
         			[TD="class: LogEntry1, bgcolor: #ffffff, colspan: 8, align: left"][SIZE=12px][FONT=Courier-New][COLOR=#FF0000]Running script(2) &hs.writelog("test", "123") : hs.writelog("test", "456"), init error: Syntax error[/COLOR][/FONT][/SIZE][/TD]
         		[/TR]
        [/TABLE]
        [TABLE="class: log_table_row, width: 970"]
        [TR]
        [TD="class: LogDateShort LogDateTime0, bgcolor: #ffffff, align: left"][SIZE=13px][FONT=Courier-New][COLOR=#000000]Nov-14 16:27:27[/COLOR][/FONT][/SIZE][/TD]
         			[TD="class: LogPri0, bgcolor: #ffffff, align: left"] [/TD]
         			[TD="class: LogType0, bgcolor: #ffffff, colspan: 3, align: left"][SIZE=12px][FONT=Courier-New][COLOR=#000000]Event[/COLOR][/FONT][/SIZE][/TD]
         			[TD="class: LogEntry0, bgcolor: #ffffff, colspan: 8, align: left"][SIZE=12px][FONT=Courier-New][COLOR=#000000]Running script statement immediately: &hs.writelog("test", "123") : hs.writelog("test", "456")[/COLOR][/FONT][/SIZE][/TD]
         		[/TR]
        [/TABLE]

        PS. How does one get to an HS4 Help file? Starting from Tools->Help seems to be a dead end.
        "Get Support Now" opens "Support Home Page", but "Documentation > HS4 Software > Online Help Files" yields no HS4 articles.

        Comment


          #5
          Originally posted by zwolfpack View Post
          What help file is this from??
          I found it here:

          Click image for larger version

Name:	scripting.png
Views:	382
Size:	104.1 KB
ID:	1433568

          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


            #6
            Originally posted by Uncle Michael View Post
            I'm not sure you can manipulate a return variable in an immediate script statement, because you need to declare the variable. You will probably have to create a short script and run it explicitly. (That's how I do it.)
            You could try to add Dim INTR As Integer; between the & and the assignment statement to see what happens.

            Code:
            Public Sub Main(ByVal Parms As Object)
            
            Dim Google As String = "8.8.8.8"
            Dim intR As Integer
            
            intR = hs.Ping(Google)
            
            If intR = 0 Then
            'hs.WriteLog ("Internet", "OK")
            hs.SetDeviceValueByRef(1657, 0, True)
            Else
            hs.WriteLog ("Internet", "??")
            hs.SetDeviceValueByRef(1657, 100, True)
            End If
            
            End Sub
            Thanks, gang, I already have a scripted version for checking the Internet, I was just thinking I'd try an immediate version....in fact, I can't even remember why. What I need to do is admit I don't know squat about scripting any more. Wasn't this a lot easier in HS2?

            Can anyone direct me to a "Dummies" course on VB SCRIPT? (That so-called "Help File" referenced herein is really thin.)


            Jim Speiser
            38-year veteran of Home Automation
            Still don't know squat

            Comment


              #7
              Try doing a web search for vb.net tutorial. There are lots of choices, but I find most of them aimed at people looking for a more comprehensive understanding.
              Here's one: https://www.tutorialspoint.com/vb.net/index.htm

              I'd also suggest taking a look at tenScripting.
              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


                #8
                My opinion (worth about a Guinea Franc) is that you have to dive-in. I have built a bit of a toolbox that I can utilize such as pass parameters from both events and HSTouch, how CAPIControl works, creating ini files and global variables, and how to manipulate the VGPair for a device. I am a by example coder and spend time searching in the forum and googling to find example of how to accomplish tasks. I am will willing to share all my scripts and I suspect most others are willing to do so. I have also used HS features to run perl scripts and other programs from events.

                I have received significant help on coding problems in the forum and will reciprocate where possible.

                Regards

                Comment


                  #9
                  Originally posted by AllHailJ View Post
                  My opinion (worth about a Guinea Franc) is that you have to dive-in. I have built a bit of a toolbox that I can utilize such as pass parameters from both events and HSTouch, how CAPIControl works, creating ini files and global variables, and how to manipulate the VGPair for a device. I am a by example coder and spend time searching in the forum and googling to find example of how to accomplish tasks. I am will willing to share all my scripts and I suspect most others are willing to do so. I have also used HS features to run perl scripts and other programs from events.

                  I have received significant help on coding problems in the forum and will reciprocate where possible.

                  Regards
                  Thanks for the offer, I may take you up on it. Believe it or not, I was once a Java instructor, but I think vb script is a bit more...involved. Besides, that was 20 years ago. I think I have all the major concepts down, I just need to, like you said, immerse myself in the lexicon. Meantime, like you, I've been stealing code from here and there.

                  Thanks again,
                  Jim Speiser
                  Former Java Instructor and
                  Hair Coloring Consultant to Rudy Giuliani


                  Jim Speiser
                  38-year veteran of Home Automation
                  Still don't know squat

                  Comment


                    #10
                    Originally posted by Uncle Michael View Post
                    Try doing a web search for vb.net tutorial. There are lots of choices, but I find most of them aimed at people looking for a more comprehensive understanding.
                    Here's one: https://www.tutorialspoint.com/vb.net/index.htm

                    I'd also suggest taking a look at tenScripting.
                    OK, my first question is, why do I want vb.net vs. vb script?


                    Jim Speiser
                    38-year veteran of Home Automation
                    Still don't know squat

                    Comment


                      #11
                      vb.net is the current "successor" to VBS. Although VBS is still supported by HS, some HS functions require vb.net. (The script I posted is a vb.net script.)
                      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


                        #12
                        From https://stackoverflow.com/questions/...ipt-and-vb-net

                        Compilation logistics of VB series of languages :

                        Visual Basic => Compiled to native code packaged inside *.dll or *.exe files.

                        VB script => An interpreted language. It is not compiled. You can get more details here

                        Visual Basic .NET => VB .NET is compiled to MSIL (Microsoft Intermediate Language) code (similar to byte code in Java world) packaged inside *.dll or *.exe files.

                        From what I have read, C# was the language written for .NET but they needed to save existing code-bases so they added VB.net as well. VB.net is compiled and that makes it faster. I considered C# but VB.net seemed easier and there seemed to be more people in the HS community using VB.net. I know C, Fortran, Pascal, and Basic (many years since I programmed though) so I went with VB.net.

                        Comment


                          #13
                          Originally posted by Uncle Michael View Post
                          vb.net is the current "successor" to VBS. Although VBS is still supported by HS, some HS functions require vb.net. (The script I posted is a vb.net script.)
                          OK, is there a way to tell if an HS function will or will not work in VBS? I'd prefer the simplest language for now, and that is definitely VBS.


                          Jim Speiser
                          38-year veteran of Home Automation
                          Still don't know squat

                          Comment


                            #14
                            Originally posted by AllHailJ View Post
                            From https://stackoverflow.com/questions/...ipt-and-vb-net




                            From what I have read, C# was the language written for .NET but they needed to save existing code-bases so they added VB.net as well. VB.net is compiled and that makes it faster. I considered C# but VB.net seemed easier and there seemed to be more people in the HS community using VB.net. I know C, Fortran, Pascal, and Basic (many years since I programmed though) so I went with VB.net.
                            Yeah, I've looked at C#, and oh, brother. I remember there was a problem just with the name of the language, you couldn't even name a folder because of the "#" symbol. Plus, I tend to compare everything with Java, and in terms of "elegance", nothing comes close...and C# is the furthest away!


                            Jim Speiser
                            38-year veteran of Home Automation
                            Still don't know squat

                            Comment


                              #15
                              Originally posted by JimSpy View Post
                              is there a way to tell if an HS function will or will not work in VBS?
                              I'm not aware of it if there is one. . .except for the always-reliable "try it and see"
                              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

                              Working...
                              X