Announcement

Collapse
No announcement yet.

Help needed figuring out 2 errors...

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

    Help needed figuring out 2 errors...

    Script attached - I suspect I'm missing something simple? TIA!

    Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\AirscapeUpdate.vb: Statement cannot appear within a method body. End of method assumed.

    Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\AirscapeUpdate.vb: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
    Attached Files

    #2
    Originally posted by Ltek View Post
    Script attached - I suspect I'm missing something simple? TIA!
    At first glance, you have 3 "Subs", but only 1 "End Sub". they must be paired.

    Comment


      #3
      I'm not sure that this is your problem but in VB.net I think you need to explicitly declare variables.

      Dim FanIP = "192.168.2.143" probably should be
      Dim FanIP As String = "192.168.2.143".

      Have you tried tenScripting? If not you might find Ed's stuff great tools.

      By the way, your code is super readable; wish my stuff was as organized.
      Don

      Comment


        #4
        Nice job of documenting your code!

        1) Each Sub or Function block must start with the Sub or Function keyword and end with the corresponding End Sub or End Function keywords. You intended to have 3 code blocks but have only one End Sub at the end. (Note that Try/Catch/End Try does not serve this purpose). This is the reason for the "Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\AirscapeUpdate.vb: Statement cannot appear within a method body. End of method assumed." error as the compiler sees the statements 'Sub FanControl(...)" and 'Sub Update()' within the 'Main()' code block.

        2) Subs are code blocks that do not return a value. Functions are like subs but return a value. In HS 'scripting' the Main() block must always be a Sub. In your code, FanControl() does not return any values so it can remain a Sub, however, Update() returns the value FanSpd so it should be a Function.

        3) Dim statements should appear inside of Sub / End Sub or Function / End Function blocks and these vars are local, ie; only visible to the code within that code block. Use the keyword Const instead for global values (that do not change) which allows all Subs and Functions access to the value.

        Here is the basic structure of a HS VB.Net "script":
        Code:
        Sub Main(ByVal params As Object)
        	Dim ...
        	Dim ...
        
        	Your Code...
        End Sub
        
        Sub SomeSub(ByVal LocalVar As String)
        	Dim ...
        	Your Code...
        End Sub
        
        Function MyFunction(ByVal LocalVar As Integer) As String
        	Dim MyLocalVar As String
        	Your Code ...
        	Return MyLocalVar
        End Function
        I have attached a revised version of your code that attempts to address the major issues listed above. I have not run this so there are likely still errors to address, but it will give you an idea of how to structure your code using Subs and Functions and how to create local variables.
        Attached Files
        Best regards,
        -Mark-

        If you're not out on the edge, you're taking up too much room!
        Interested in 3D maps? Check out my company site: Solid Terrain Modeling

        Comment


          #5
          Mark,
          Thanks so much for the help. I used to be a good script monkey, believe it or not... back in HS1 days.

          In your edits, I found a few items not declared so I fixed. BUT still getting errors...

          First, I was getting...

          Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\Airscape_test.vb: 'ex' is not declared. It may be inaccessible due to its protection level.
          .. I found the issue, I was using ex before the Catch, thus it was no yet declared. AND I could not declare it otherwise I got error "Variable 'ex' hides a variable in an enclosing block. " -- no biggie, I just removed that Log.


          BUT still getting...

          statement cannot appear within a method body. End of method assumed.

          &

          Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

          Comment


            #6
            Figured it out... there was a missing End Sub ... so easy to miss those things!

            Its all working now!

            thank you a ton. Now I can dive into my next script - which should be more useful to others.

            Comment


              #7
              Sorry about the errors, I guess I shouldn't be coding before coffee

              Glad you got it working!
              Best regards,
              -Mark-

              If you're not out on the edge, you're taking up too much room!
              Interested in 3D maps? Check out my company site: Solid Terrain Modeling

              Comment


                #8
                I spoke too soon... it ALMOST fully works.

                When running Main, it works fine

                When only running 'Update' it fails...

                Running script C:\Program Files (x86)\HomeSeer HS3\scripts\AirscapeControl.vb :Parameter count mismatch.->Does entry point Update exist in script? at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Obj ect obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at A.c17b105f989efe61e5979e67bec1ef734.cffd66cb0782c50126727e3f a75582d7a()

                Comment


                  #9
                  Sorry, I forgot that you might be calling the subs from outside of HS. Because HS expects to pass a parameter string to all subs that it calls, you'll need to add 'ByVal param As Object' to the function and pass an empty string ("") when calling the sub from within the script. Try changing:
                  Function Update() As Integer
                  to
                  Function Update(ByVal param As Object) As Integer

                  and then change the line under Case "SET" in Main() from
                  fanspd = Update()
                  to
                  fanspd = Update("")

                  Note that trying to call Sub FanControl(ByVal Number As Integer, ByVal SpeedDiff As Integer, ByVal FanAction As String, ByVal LogMsg As String) from HS may also fail since I believe HS can only pass a single parameter and the Sub is expecting 4 params. If you want to call this one as well then we'll need to add another Sub as the entry point for HS calls to this Sub.
                  Best regards,
                  -Mark-

                  If you're not out on the edge, you're taking up too much room!
                  Interested in 3D maps? Check out my company site: Solid Terrain Modeling

                  Comment


                    #10
                    Thanks again. Only calling Update separately so users can run a reoccurring event to update vDevices on a cadence.

                    Sent from my SAMSUNG-SM-G935A using Tapatalk

                    Comment

                    Working...
                    X