Announcement

Collapse
No announcement yet.

Calling a script from within another script

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

    Calling a script from within another script

    I have a script that I would like to call from several other scripts (So I don't have to duplicate the code in each script). What is the proper way to call another script in a script?

    Example: There's a script that checks how many email messages you have, and tells you who they're from. You may want to call this script
    1) from your "Morning Announcements" script,
    2) from your "Incoming email" script, and
    3) from your "Returning home" script.

    Thanks in advance

    #2
    If the script does not require any parameters then use:
    PHP Code:
    hs.Run "checkmessages.txt" 
    if the script requires some input parameter then use
    PHP Code:
    hs.RunEx "checkmessages.txt","main","inputparm" 

    Comment


      #3
      sub main()
      hs.Run "lights_off.txt"
      end sub


      example from the homeseer users guide
      https://forums.homeseer.com/forum/de...plifier-plugin

      Comment


        #4
        Thanks gentlemen - such an easy command, but for some reason it got the best of me. I appreciate the help (a lot!)

        Comment


          #5
          Hello,

          I want the same only with a vb script
          Run a script from a Script

          Sub Main()

          hs.Run (DJ_Update_Counter_06.vb("Main","clear|r1")
          hs.Run (DJ_Update_Counter_06.vb("Main","clear|r2")

          End Sub

          When I run the script I must declare DJ_Update_Counter_06.vb
          Script compile error: Name 'DJ_Update_Counter_06' is not declared.on line 16

          Is there somebody know how to do this.

          Thanks Ed

          Comment


            #6
            Originally posted by ESSCHENK View Post
            Hello,

            I want the same only with a vb script
            Run a script from a Script

            Sub Main()

            hs.Run (DJ_Update_Counter_06.vb("Main","clear|r1")
            hs.Run (DJ_Update_Counter_06.vb("Main","clear|r2")

            End Sub

            When I run the script I must declare DJ_Update_Counter_06.vb
            Script compile error: Name 'DJ_Update_Counter_06' is not declared.on line 16

            Is there somebody know how to do this.

            Thanks Ed
            It looks like you are missing some parenthesis and quotes.

            This is untested but try:
            Code:
            Sub Main()
            
            hs.Run ("DJ_Update_Counter_06.vb("Main","clear|r1")")
            hs.Run ("DJ_Update_Counter_06.vb("Main","clear|r2")")
            
            End Sub
            💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

            Comment


              #7
              I believe the correct syntax would be:
              Code:
              Sub Main()
               hs.RunEx "DJ_Update_Counter_06.vb","Main","clear|r1"
               hs.RunEx "DJ_Update_Counter_06.vb","Main","clear|r2"
              End Sub
              hs.Run only accepts the script name (no parameters.)

              hs.RunEx accepts the script name, a function within the script and parameters.

              From the HomeSeer Help file (under Scripting):
              RunEx


              This function runs a function in a script with a parameter. This will also return a value from the called script.
              • Scripts must be located in the scripts directory in the HomeSeer application directory (C:\Program Files\HomeSeer 2\Scripts by default).
              Parameters
              Parameter: scr
              Type: string
              Description: This is the file name of the script to run. Do not include the path in the script name.

              Parameter: func
              Type: string
              Description: This is the name of the function to execute.

              Parameter: param
              Type: variant
              Description: This is a parameter to send to the function. This can be a string or numeric value.
              Returns
              Return value: value
              Type: variant
              Description: This returns any value that the called script returns.
              Example

              Consider the following script named test.txt:
              launch_app(appname)
              hs.Launch appname
              ' now return some text to the caller
              launch_app = "The application is launched"

              end sub
              The above script could be called using the RunEx call from another script like:
              sub main()
              dim s
              ' call the script and get the return value

              s = hs.RunEx("test.txt","launch_app","notepad.exe")

              ' display the returned string
              msgbox s
              end sub
              Also, in VBscript, parantheses are not used around the parameters for a function unless the function is returning something, like this:
              Code:
              retval = hs.RunEx ("DJ_Update_Counter_06.vb","Main","clear|r2")
              Where retval would contain whatever was returned by the script when it finished.
              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
                Thanks for the Quick answer,

                @Rub,
                I get the following error,

                Sub Main()
                hs.Run ("DJ_Update_Counter_06.vb("Main","clear|r1")")
                hs.Run ("DJ_Update_Counter_06.vb("Main","clear|r2")")
                End Sub


                Option Strict Offimports Schedulerimports SystemPublic Module scriptcode32#Region "Automatically generated code, do not modify"'Automatically generated code, do not modify'Event Sources Begin <system.contextstaticattribute()>Public WithEvents hs As Scheduler.hsapplication <system.contextstaticattribute()>Public WithEvents hsp As scheduler.hsp <system.contextstaticattribute()>Public WithEvents hssystem As scheduler.phone0'Event Sources End'End of automatically generated code#End RegionSub Main()hs.Run ("DJ_Update_Counter_06.vb("Main","clear|r1")")hs.Run ("DJ_Update_Counter_06.vb("Main","clear|r2")")End SubEnd Module</system.contextstaticattribute()></system.contextstaticattribute()></system.contextstaticattribute()>

                Script compile error: Comma, ')', or a valid expression continuation expected.on line 16




                <link rel="File-List" href="file:///C:%5CDOCUME%7E1%5Ced%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cc lip_filelist.xml"><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <wontGrowAutofit/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><style> <!-- /* Font Definitions */ @font-face {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:536871559 0 0 0 415 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:595.3pt 841.9pt; margin:70.85pt 70.85pt 70.85pt 70.85pt; mso-header-margin:35.4pt; mso-footer-margin:35.4pt; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:Standaardtabel; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->@mark


                Sub Main()
                hs.RunEx "DJ_Update_Counter_06.vb","Main","clear|r1"
                hs.RunEx "DJ_Update_Counter_06.vb","Main","clear|r2"
                End Sub

                When i try yours i get the following error,
                <system.contextstaticattribute()><system.contextstaticattrib ute()><system.contextstaticattribute()>
                </system.contextstaticattribute()></system.contextstaticattribute()></system.contextstaticattribute()>
                <link rel="File-List" href="file:///C:%5CDOCUME%7E1%5Ced%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cc lip_filelist.xml"><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <wontGrowAutofit/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><style> <!-- /* Font Definitions */ @font-face {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:536871559 0 0 0 415 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:612.0pt 792.0pt; margin:70.85pt 70.85pt 70.85pt 70.85pt; mso-header-margin:35.4pt; mso-footer-margin:35.4pt; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:Standaardtabel; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->Option Strict Offimports Schedulerimports SystemPublic Module scriptcode31#Region "Automatically generated code, do not modify"'Automatically generated code, do not modify'Event Sources Begin <system.contextstaticattribute()>Public WithEvents hs As Scheduler.hsapplication <system.contextstaticattribute()>Public WithEvents hsp As scheduler.hsp <system.contextstaticattribute()>Public WithEvents hssystem As scheduler.phone0'Event Sources End'End of automatically generated code#End RegionSub Main() hs.RunEx "DJ_Update_Counter_06.vb","Main","clear|r1" hs.RunEx "DJ_Update_Counter_06.vb","Main","clear|r2"End SubEnd Module</system.contextstaticattribute()></system.contextstaticattribute()></system.contextstaticattribute()>

                <link rel="File-List" href="file:///C:%5CDOCUME%7E1%5Ced%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cc lip_filelist.xml"><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <wontGrowAutofit/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><style> <!-- /* Font Definitions */ @font-face {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:536871559 0 0 0 415 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:612.0pt 792.0pt; margin:70.85pt 70.85pt 70.85pt 70.85pt; mso-header-margin:35.4pt; mso-footer-margin:35.4pt; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:Standaardtabel; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->Script compile error: Method arguments must be enclosed in parentheses.on line 15

                I cant find the reason why it is not working.


                Thanks Ed

                Comment


                  #9
                  Without trying this again. Try this.

                  Sub Main()
                  hs.Run ("DJ_Update_Counter_06.vb(""Main"",""clear|r1"")")
                  hs.Run ("DJ_Update_Counter_06.vb(""Main"",""clear|r2"")")
                  End Sub
                  💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

                  Comment


                    #10
                    Hello,

                    Still no luck

                    Sub Main()

                    hs.Run ("DJ_Update_Counter_06.vb(""Main"",""clear|r1"")")
                    hs.Run ("DJ_Update_Counter_06.vb(""Main"",""clear|r2"")")

                    End Sub



                    Scripting runtime error: System.Reflection.TargetParameterCountException: Parameter count mismatch. at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at Scheduler.VsaScriptHost.Invoke(String ModuleName, String MethodName, Object[] Arguments)


                    Ed

                    Comment


                      #11
                      The correct method should be:

                      hs.RunEx ("DJ_Update_Counter_06.vb","Main","clear|r1")
                      Jon

                      Comment


                        #12
                        Hello Jon,

                        Also with this example it's stil not working.

                        When i run the script from a event al is working fine
                        But i want it to run from a script because it's easy to edit from a script with more then 20 counters
                        <table width="0%" border="1" cellpadding="0" cellspacing="1"><tbody><tr> <td colspan="4" align="middle">Action List </td></tr><tr> <td colspan="4" align="right"><input class="graphicbutton" value="0" alt="Execute this event now" src="/images/HomeSeer/button_test.gif" name="action_test_event" type="image"> </td></tr> <form method="post" name="actionform"></form><input value="actn2799" name="ref_page" type="hidden"> <tr> <td><input class="graphicbutton" value="1" alt="Down" src="/images/HomeSeer/thread_priority_down.gif" name="action_down" type="image"> </td> <td><input value="1" name="action_index" type="hidden"><input class="graphicbutton" value="1" alt="Delete this Action" src="/images/HomeSeer/button_delete.gif" name="action_delete" type="image"> </td> <td><input class="graphicbutton" value="Edit" alt="Edit this Action" src="/images/HomeSeer/button_edit.gif" name="action_edit" type="image"> </td> <td> <table width="0%" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="tablecellscript" width="160" align="right" nowrap="nowrap"> Run script:</td> <td class="tablecellscript" align="left">DJ_Update_Counter_06.vb("Main","clear|r1")</td></tr></tbody></table></td></tr><input value="actn2799" name="ref_page" type="hidden"> <form method="post" name="actionform"></form><input value="actn2799" name="ref_page" type="hidden"> <tr> <td><input class="graphicbutton" value="2" alt="Up" src="/images/HomeSeer/thread_priority_up.gif" name="action_up" type="image"> <input class="graphicbutton" value="2" alt="Down" src="/images/HomeSeer/thread_priority_down.gif" name="action_down" type="image"> </td> <td><input value="2" name="action_index" type="hidden"><input class="graphicbutton" value="2" alt="Delete this Action" src="/images/HomeSeer/button_delete.gif" name="action_delete" type="image"> </td> <td><input class="graphicbutton" value="Edit" alt="Edit this Action" src="/images/HomeSeer/button_edit.gif" name="action_edit" type="image"> </td> <td> <table width="0%" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="tablecellwait" width="160" align="right" nowrap="nowrap"> Wait:</td> <td class="tablecellwait" align="left">100 milliseconds</td></tr></tbody></table></td></tr><input value="actn2799" name="ref_page" type="hidden"> <form method="post" name="actionform"></form><input value="actn2799" name="ref_page" type="hidden"> <tr> <td><input class="graphicbutton" value="3" alt="Up" src="/images/HomeSeer/thread_priority_up.gif" name="action_up" type="image"> <input class="graphicbutton" value="3" alt="Down" src="/images/HomeSeer/thread_priority_down.gif" name="action_down" type="image"> </td> <td><input value="3" name="action_index" type="hidden"><input class="graphicbutton" value="3" alt="Delete this Action" src="/images/HomeSeer/button_delete.gif" name="action_delete" type="image"> </td> <td><input class="graphicbutton" value="Edit" alt="Edit this Action" src="/images/HomeSeer/button_edit.gif" name="action_edit" type="image"> </td> <td> <table width="0%" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="tablecellscript" width="160" align="right" nowrap="nowrap"> Run script:</td> <td class="tablecellscript" align="left">DJ_Update_Counter_06.vb("Main","clear|r3")</td></tr></tbody></table></td></tr><input value="actn2799" name="ref_page" type="hidden"> <form method="post" name="actionform"></form><input value="actn2799" name="ref_page" type="hidden"> <tr> <td><input class="graphicbutton" value="4" alt="Up" src="/images/HomeSeer/thread_priority_up.gif" name="action_up" type="image"> <input class="graphicbutton" value="4" alt="Down" src="/images/HomeSeer/thread_priority_down.gif" name="action_down" type="image"> </td> <td><input value="4" name="action_index" type="hidden"><input class="graphicbutton" value="4" alt="Delete this Action" src="/images/HomeSeer/button_delete.gif" name="action_delete" type="image"> </td> <td><input class="graphicbutton" value="Edit" alt="Edit this Action" src="/images/HomeSeer/button_edit.gif" name="action_edit" type="image"> </td> <td> <table width="0%" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="tablecellwait" width="160" align="right" nowrap="nowrap"> Wait:</td> <td class="tablecellwait" align="left">100 milliseconds</td></tr></tbody></table></td></tr><input value="actn2799" name="ref_page" type="hidden"> <form method="post" name="actionform"></form><input value="actn2799" name="ref_page" type="hidden"> <tr> <td><input class="graphicbutton" value="5" alt="Up" src="/images/HomeSeer/thread_priority_up.gif" name="action_up" type="image"> <input class="graphicbutton" value="5" alt="Down" src="/images/HomeSeer/thread_priority_down.gif" name="action_down" type="image"> </td> <td><input value="5" name="action_index" type="hidden"><input class="graphicbutton" value="5" alt="Delete this Action" src="/images/HomeSeer/button_delete.gif" name="action_delete" type="image"> </td> <td><input class="graphicbutton" value="Edit" alt="Edit this Action" src="/images/HomeSeer/button_edit.gif" name="action_edit" type="image"> </td> <td> <table width="0%" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="tablecellscript" width="160" align="right" nowrap="nowrap"> Run script:</td> <td class="tablecellscript" align="left">DJ_Update_Counter_06.vb("Main","clear|r5")</td></tr></tbody></table></td></tr></tbody></table>




                        Originally posted by jon00 View Post
                        The correct method should be:

                        hs.RunEx ("DJ_Update_Counter_06.vb","Main","clear|r1")

                        Scripting runtime error: System.Reflection.TargetParameterCountException: Parameter count mismatch. at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at Scheduler.VsaScriptHost.Invoke(String ModuleName, String MethodName, Object[] Arguments)

                        Thanks Ed

                        Comment


                          #13
                          I just tested this here and it works.

                          Code:
                          Sub Main(parm as object)
                          hs.runEx("test.vb","Main","clear|r1")
                          End Sub
                          
                          Contents of text.vb
                          Sub Main(parm as object)
                          hs.writelog("info", parm)
                          End Sub
                          💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

                          Comment


                            #14
                            Just to clarify, what is the file extension for this script (not DJ_Update_Counter_06.vb)? Is it .txt, .vbs, .vb, .asp, or something else? This determines which scripting language is being interpreted, and could be the reason for each of us recommending different syntax for calling your script.

                            It looks like there is a mismatch between the number of parameters you're calling with and what DJ_Update_Counter_06.vb requires as evidenced by the first line of the error message:
                            Scripting runtime error: System.Reflection.TargetParameterCountException: Parameter count mismatch.
                            Can you please post the beginning part of the code for DJ_Update_Counter_06.vb (ie; the start of 'main') so that we can see which parameters are required and their types?
                            Last edited by mfisher; January 10, 2010, 12:26 PM.
                            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


                              #15

                              Comment

                              Working...
                              X