Announcement

Collapse
No announcement yet.

vb.net class construct?

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

    vb.net class construct?

    Please correct me if I'm wrong, but as I understand how creating a vb.net script works with Homeseer its essentially creating a class without the Class and End Class statements.

    Can we use the vb.net constructor (new)?

    For example, I want to populate a couple of global arrays based on current conditions that will be available to all functions and subs in this class.

    #2
    Yes, you can use the New constructor. You might have to add a class/namespace reference to your settings.ini depending on the classes you want to use though.
    HS4Pro on a Raspberry Pi4
    54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
    Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

    HSTouch Clients: 1 Android

    Comment


      #3
      My apologies.

      After re-reading my question it was not very clear at all.

      Here is an example that may help clarify my question.

      (please forgive code typo's. I just created this for the purpose of clarifying my question).

      Code:
      Private myvar1 as string
      
          Public Sub New()
              myvar1 = "my first event"
          End Sub
      
          Public Sub enableEvent(ByVal params As String)
              hs.EnableEvent(myvar1)
          End Sub
      
          Public Sub disableEvent(ByVal params As String)
              hs.DisableEvent(myvar1)
          End Sub
      In this case when I call enableEvent or disableEvent will myvar1 be populated?

      Comment


        #4
        Originally posted by sifuhall View Post
        My apologies.

        After re-reading my question it was not very clear at all.

        Here is an example that may help clarify my question.

        (please forgive code typo's. I just created this for the purpose of clarifying my question).

        Code:
        Private myvar1 as string
        
            Public Sub New()
                myvar1 = "my first event"
            End Sub
        
            Public Sub enableEvent(ByVal params As String)
                hs.EnableEvent(myvar1)
            End Sub
        
            Public Sub disableEvent(ByVal params As String)
                hs.DisableEvent(myvar1)
            End Sub
        In this case when I call enableEvent or disableEvent will myvar1 be populated?
        That will work as long as you call the New() sub at one time. However, it can be any sub you want...
        HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
        Running on Windows 10 (64) virtualized
        on ESXi (Fujitsu Primergy TX150 S8).
        WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

        Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

        Comment


          #5
          Why not just pass myvar1 into the functions via the params variable?
          💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

          Comment


            #6
            Originally posted by Rupp View Post
            Why not just pass myvar1 into the functions via the params variable?
            Because you might want to do it with more variables. And that's when passing the variables might get messy...
            HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
            Running on Windows 10 (64) virtualized
            on ESXi (Fujitsu Primergy TX150 S8).
            WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

            Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

            Comment


              #7
              Pass them in as an array or collections and split them.
              💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

              Comment


                #8
                That's what I am trying to avoid.

                I want to create the ability to affect many devices based on location or any other criteria I specify.

                To do this I want to populate either a multidimensional array, or maybe a struct, or list, etc (that part isn't important right now).

                And in whatever storage method I choose (array, struct, list, etc) I will define properties of that object.

                For example, this layout is name, device id, location, include in turn off:
                "Kitchen Main Light", "Q1", "Kitchen", 1
                "Kitchen Basin Lignt", "Q2", "Kitchen", 0
                "Living Room Main Light", "Q3", "Living Room", 1
                "Front Porch Light", "Q4", "Outside", 0

                Please keep in mind that I currently have over 50 devices so I'm looking to keep this as clean and maintainable as I can.

                Now, using this information I can create code to do things like:
                Turn off everything in a specific location
                Turn off all lights (except the lights I want to always leave on which are identified by a 0 in the field include in turn off.
                Turn on everything in a specific location
                Etc

                What I want to do is define this variable (again it could a multidimensional array, struct, list, etc) in one place and just reference the data in it.

                That way when I add new devices, like say a new light in the kitchen, I can update this single place and all my events will still work and it will be included when I shut of all lights or just all kitchen lights.

                Since the code is very similar to a VB.Net class I was hoping I could use the constructor so when the class is initialized it would automatically call the contructor method and that would give me a single place to manage all my devices.

                Comment


                  #9
                  Originally posted by Rupp View Post
                  Pass them in as an array or collections and split them.
                  That does not always make sense.

                  Say that you have some routine that actually does something to the data stored in the variables, you would need to return them, store them somehow in HomeSeer, and then pass them back on the next time you are using then.

                  Not practical, more close to hard to achieve...

                  See my sunshine alarm clock script as an example:
                  http://board.homeseer.com/showpost.p...4&postcount=30
                  HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
                  Running on Windows 10 (64) virtualized
                  on ESXi (Fujitsu Primergy TX150 S8).
                  WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

                  Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

                  Comment


                    #10
                    From basic testing it appears Homeseer does call the class construct so this may make my job a lot easier.

                    Here is my test code:

                    Code:
                    Private myDevices(1,5) as string
                    
                    
                    
                    	Sub New()
                    		myDevices(0,0) = "Q11"
                    	End Sub
                    	
                    	Public Sub test_new(ByVal params As String)
                    		hs.Transmit(myDevices(0,0), "Off")
                    	End Sub
                    I created an event to call the sub test_new and the device code was populated.

                    Comment


                      #11
                      Originally posted by Moskus View Post
                      That does not always make sense.

                      Say that you have some routine that actually does something to the data stored in the variables, you would need to return them, store them somehow in HomeSeer, and then pass them back on the next time you are using then.

                      Not practical, more close to hard to achieve...

                      See my sunshine alarm clock script as an example:
                      http://board.homeseer.com/showpost.p...4&postcount=30
                      Huh? The OP wants to store a variable that is passed in. Why would you need this extra step? Simply pass the name directly into the sub. Why go the extra step of setting the variable in his posted example?
                      💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

                      Comment


                        #12
                        My original question was if I could use the built in class contruct method to load vars that will then be available to routines in this script.

                        It seems to be working well based on very limited testing so far.

                        Comment


                          #13
                          Originally posted by Rupp View Post
                          Huh? The OP wants to store a variable that is passed in. Why would you need this extra step? Simply pass the name directly into the sub. Why go the extra step of setting the variable in his posted example?
                          Well... Perhaps because it lets you set more than one variable? Or is easier to deal with than referencing a variable all the time?


                          Originally posted by sifuhall View Post
                          My original question was if I could use the built in class contruct method to load vars that will then be available to routines in this script.

                          It seems to be working well based on very limited testing so far.
                          It should work, I've had no problems with it.
                          HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
                          Running on Windows 10 (64) virtualized
                          on ESXi (Fujitsu Primergy TX150 S8).
                          WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

                          Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

                          Comment

                          Working...
                          X