5 Replies Latest reply on Jun 18, 2010 11:33 AM by patrick.cashman

    VB6 Automation template for BSRE needed

    patrick.cashman

      I have been going around and around trying to get a VB6 project template to work with BSRE.  It seems to come down to issues with

       

      Dim app As MGCPCB.BoardstationREApplication

       

      and

       

      Set app = GetObject(, "MGCPCB.BoardStationREApplication")

       

      but no matter what I've tried so far, I get failure to launch.

       

       

      There are a lot of examples in the BSXE2007 installation  path, but they seem to have been written primarily for Expedition, and I  have not been able to invoke any of them on BSRE.

       

       

       

      So if anyone has a working VB6 project with the basics of an Automation interface to BSRE, I'd sure appreciate it.

       

       

      Thanks,

       

      Patrick

        • 1. Re: VB6 Automation template for BSRE needed
          ed_smith

          Patrick,

           

          I'm not sure what you mean by, "I get failure to launch" but if you are trying to launch an instance of BSRE then you should use CreateObject rather than GetObject. If you use GetObject then the application must be running already... I believe you have specified the correct (so-called) ProgID (MGCPCB.BoardStationREApplication).

           

          Regards, Ed

          • 2. Re: VB6 Automation template for BSRE needed
            patrick.cashman

            Hi Ed,

             

            Thanks for the reply.  I have BSRE running  when I start the VB application.  What I meant was that the VB app  doesn't start.

             

            What I have is a project with 1 module  with the following code:

             

             

             

            Option  Explicit

             


            Public app As MGCPCB.BoardStationREApplication
            Public doc As MGCPCB.Document

             

            Public Function GetLicensedDoc(app)
                 On Error Resume Next
                 Dim key, licenseServer, licenseToken, doc
                 Set GetLicensedDoc = Nothing
                 'collect the active document
                 Set app = GetObject(, "MGCPCB.BoardStationREApplication")
                 Set doc = app.ActiveDocument
                 If (Err) Then
                     'Call app.Gui.StatusBarText("No active document:"  Err.Description,epcbStatusFieldError)
                     Exit Function
                 End If
                 'Ask Expedition’s document for the key
                 key = doc.Validate(0)
                 'Get token from license server
                 Set licenseServer =  CreateObject("MGCPCBAutomationLicensing.Application")
                 licenseToken = licenseServer.GetToken(key)
                 Set licenseServer = Nothing
             
                 'Ask the document to validate the license token
                 Err.Clear
                 doc.Validate (licenseToken)
                 If (Err) Then
                     'Call app.Gui.StatusBarText("No active document license: "  Err.Description,epcbStatusFieldError)
                     Exit Function
                 End If
             
                 'everything is OK, return document
                 Set GetLicensedDoc = doc
            End Function

             

             

             

            Then I have a  simple form with 1 button and this code:

             

             

             

            Private  Sub cmd_get_info_Click()
                 Dim tmp As String
                 tmp = doc.FullName
                 MsgBox ("fullname is " & tmp)
            End Sub

             

             

             

            When I run the  application, it starts, but when I press the button, I get the "Object  variable or With block variable not set" error.

             

            Any  ideas you may have on this would be most welcome.

             

            Thank  you,

             

            Patrick

            • 3. Re: VB6 Automation template for BSRE needed
              ed_smith

              Patrick,

               

              I am unsure whether you have included 100.0% of the source but if you have then it is probably failing on the line "tmp = doc.FullName". The reason is that the doc object is never initialized (it is created but not initialized). Looking at your code I think you need to make a call to GetLicensedDoc - something like "doc = GetLicensedDoc(app)" just before the line "tmp = doc.FullName".

               

              Now having said that I think the intent of the GetLicensedDoc method is that you pass an Application object into it but I see you are setting it (Set app = ) inside that method. Not sure if this is going to be a problem for you down the road.

               

              I don't know whether you know but you can set breakpoints in VB6 and step through the source line by line - that will enable you to see exactly which line is causing the problem.

               

              Regards, Ed

              • 4. Re: VB6 Automation template for BSRE needed
                kendall_hiles

                Agreed.  You need to set the app and doc and call the license before it will do anything.  Look in the examples in AATK there are a a lot (most) were created in VB6 and turned into VB script to put in the forms or run stand alone.  There are a few in the %SSD_HOME% Automation Examples directory.

                • 5. Re: VB6 Automation template for BSRE needed
                  patrick.cashman

                  Brilliant. It works with

                   

                   

                   

                  Private Sub cmd_get_info_Click()
                      Dim tmp As String
                     
                      Set doc = GetLicensedDoc(app)
                     
                      tmp = doc.FullName
                      MsgBox ("fullname is " & tmp)
                  End Sub

                   

                   

                  Now it seems so simple, but sure has been a headbanger for a while.

                   

                  Thanks for all the help from both of you,

                   

                  Patrick