3 Replies Latest reply on Jun 19, 2015 7:10 AM by Sethu Raman

    New to VB, and the Solidworks API...

    Aaron Torberg

      Okay, I am learning this stuff as I go and I am super new to both VB and the SolidWorks API (I began teaching myself about 2 weeks ago).  I have a Userform with two textboxs' and a button.  I want the user to enter two numeric values (integers) and hit the button to execute code based on the two variables.  I can show the userform when the macro runs, but I don't know how to get my button to be the trigger to continue running the code...?  If I close the userform my code continue and this is not desirable - I would like the macro to end if the user selects the red X in the corner of the window.

       

      I am sorry if this is super easy stuff, please go easy on me I'm trying to learn...  Thanks in advance for any help!

        • Re: New to VB, and the Solidworks API...
          Sethu Raman

          Hi Aaron,

           

          Just double click the button. method will be created automatically. Then write the code inside that method. this code will be executed while click the button.

           

          Thanks.

            • Re: New to VB, and the Solidworks API...
              Aaron Torberg

              Is it acceptable to have a majority of my code living in this method?  It feels like I should have small pieces of code living there and re-directs from my "Sub main()" to call on these actions.  I have been trying to place a majority the code below the "Sub main()".  Sort of like this...VB1.JPG

                • Re: New to VB, and the Solidworks API...
                  Sethu Raman

                  1. Double click the button. it will create "commandbutton1_click"  click event like below.

                       Private Sub CommandButton1_Click()

                       End Sub

                   

                  2. Move all code to the click event from sub main() except "userform1.show"

                       Private Sub CommandButton1_Click()

                            ''move here

                   

                            userform1.textbox = ssvalves

                            '

                            '

                            '

                            '

                            mymodelview.framestate = swwindowstate_e.swwindowmaximized.

                   

                       End Sub

                   

                  3.Now run the code from Sub main() i.e open the macro1 module and press F5. it will show form then click the button,your assembly will open.