6 Replies Latest reply on Oct 25, 2010 10:59 AM by Head1

    Running a subroutine with key combination

    Head1

      Hello everybody,

       

      During my short automation experience I have encountered small code  that runs
      a program  by typing a combination of Control + another key. ( or Alt)

      Example:
      ' ----------------------------------------------------------
      Scripting.AddTypeLibrary("MGCSDD.KeyBindings")

       

      Dim docKeyBindTableObj


      Set docKeyBindTableObj = pcbApp.Gui.Bindings("Document")

       

      Call docKeyBindTableObj.AddKeyBinding("Ctrl+M", _
      "run C:\Temp\some_program.txt",BindCommand,BindAccelerator)
      ' -----------------------------------------------------------
      This works fine.


      What I am looking for is RUNNING A SUBROUTINE with a key combination,

      while the subroutine is written next to the line that runs it. ( Not a stand alone .exe program)

       

      Example:

       

      Call docKeyBindTableObj.AddKeyBinding("Ctrl+M", "My_sub",BindCommand,BindAccelerator)  ' Probably wrong syntax

      ' -------------------------------------------------------
      Sub My_sub()

         Do_something ,,
         ..
         ..
      End sub 
      ' -------------------------------------------------------

      Whenever I try this I get an error.
      My sintax is probably wrong.

       

      Thanks for helping.

               Head1.

        • 1. Re: Running a subroutine with key combination
          AnnKinnTonn

          Hello Head1

           

          I use a VB-script to show datasheets. The (PDF) file path is stored in a parttype attribute.

          I open it by pressing F12. It works fine......

           

          That is what i do:

           

          I opened the tools -> basic scripts -> basic scripts  window. There i selected my VB-script.The name of the script is: "01 Datenblatt-Anzeige"

          It is important to have the "01" in the name!

          I enable the "In Menu" checkbox.

           

          Now i have the "01 Datenblatt-Anzeige"-script in my tools->basic scripts -menu, and because of the "01" in the name it is the first one to select.

           

          I made a Macro that executes this first basic script:

           

          Macro:

          Application.ExecuteCommand("20120")

           

          It works as long as there is no other basic-script above the "01 Datanblatt-Anzeige".

          With tools->customize... i can link the macro to a key combination (<F12> in my case).

           

          You can put another VB-script in the menu called "02 blablabla"

          it will be in the second place, because the script list is arranged in alphabetical order.

           

          The macro to start the second script is:

          Application.ExecuteCommand("20121")

           

          so you can start more scripts with macros. and start the macro with keys.

          ----

          have fun 

          • 2. Re: Running a subroutine with key combination
            Head1

            Hello Annkin Tonn,

             

               Thanks for you answer.

                I do not think I understood you answer.

             

                In short: I know  the syntax how to create a key combination ( like Ctrl + M),

                             to run a stand alone program ( like "my_program.vbs").

             

                             I do DO NOT KNOW the syntax for key combination that runs a subroutine,

                             which is written next to the line itself.

                              And this is what I am looking for.

             

              Your answer talks about different things.

             

                Thanks,

                 Head1.

            • 3. Re: Running a subroutine with key combination
              a.sassano

              How did you include you sub routine?`

               

              Only running scripts will be seen.

              But if you include scripts you must keep it running to call functions.

                           Scripting.DontExit = True

               

              I doesn't test it.

              -test.vbs-----------------------------------------------

              Sub MyTest()

                   msgbox "Startup"

              end sub

               

              '

              Call docKeyBindTableObj.AddKeyBinding("Ctrl+M", "MyTest",BindCommand,BindAccelerator)  ' Probably wrong syntax

               

              Scripting.DontExit = True
              ------------------------------------------------

              • 4. Re: Running a subroutine with key combination
                AnnKinnTonn

                Hello Head1,

                 

                I use PADS Logic.

                Maybe I didn't understand your problem because my engish is really bad, so I think I have no solution for you.

                 

                have fun,

                • 5. Re: Running a subroutine with key combination
                  Head1

                  Hello Annkin Tonn,

                   

                    You use Pads, I forgot to mention that I use Expedition 7.9.

                    Your English is not the problem in this case.

                   

                      Thanks,

                          Head1.

                  ----------------------------------------------------------------------------------

                  • 6. Re: Running a subroutine with key combination
                    Head1

                    Hello A. Sassano,

                     

                        Thanks for you reply,

                     

                          I will check you code tomorrow morning.

                     

                                 Many thanks,

                                     Head1.

                    -------------------------------------------------------------