11 Replies Latest reply on Dec 4, 2009 4:27 AM by Head1

    A question about used defined type


      Hello everybody,


      In Vb6 it is possible to define a user defined type. Example:


           Type Net_Record

               N_Name as string

               Pins() as string

               Fixed as boolean

               Tp_required as boolean

           End type



        My question: is it possible to define the same in Vbscript,

        or there is another mechanism to achieve the same?




        • 1. Re: A question about used defined type

          You can use the Class construct, which is even better than a user-defined type, because you can have public/private data members, methods, and constructors/destructors for initializing and releasing objects.  Here is an example similar to your VB6 example:


          Class Net_Record

               Public Name

               Private Pins

               Public Fixed

               Public TP_Required


               Private Sub Class_Initialize
                 Set Pins = CreateObject("Scripting.Dictionary")
               End Sub


               Public Function GetPins

                    GetPins = Pins.Keys

               End Function


               Public Function AddPin(sPinName)

                     Pins(sPinName) = sPinName

               End Function

          End Class


          When you want to create a variable for a Net_Record, use the "New" statement:


               Set netrec = New Net_Record

               netrec.Name = "CLOCK"

               netrec.AddPin "U13-33"



          • 2. Re: A question about used defined type

            Many thanks to John for your answer.

            Since I did not find anything in Vbscript, about user defined types, I assumed that the

            alternative is defining classed.




            • 3. Re: A question about used defined type

              VB script is not typed.  I develop everything in VB6 and have to comment the "AS" before VBS will accept it.



              • 4. Re: A question about used defined type

                Hi Kendall,

                   Thanks for your answer.


                     Although I know very little in Vbscript, I already feel that I prefer to program in Vb6.

                     In addition, you encouraged me when you wrote that you write everything in Vb.


                     My questions:

                             1. Can I use Vb6 Ide for writing programs, that will be linked to Expedition PCB database?

                                 I hate Vbcsript's attitude of not declaring variable types.

                             2. In case I can, the product will be an .exe file, I believe.

                                 In this case I will have to run this .exe file form some menu, Stroke or whatever  inside Pcb application.

                                 Is this the way?  It is just my guess.


                            I will be glad if you show, in a small example,  the steps in order to program with Vb6 instead of Vbscript.  


                                             Many thank,


                • 5. Re: A question about used defined type

                  Yes, you can compile VB6 into an exe and have it run.  This however will run as an out of prcess script and depending on what you are doing be extremely slow.



                  For VB6 it would look like this and you can add the reference to the AutoActive Series Type Library


                  Dim pcbApp  As MGCPCB.Application
                  Dim pcbDoc  As MGCPCB.Document



                  Sub Main()

                      'Scripting.AddTypeLibrary ("MGCPCB.Application")
                      Set pcbApp = GetObject(, "MGCPCB.Application")  'Out of process script has to find the open application
                      Set pcbDoc = pcbApp.ActiveDocument

                  end Sub



                  For VBscript it would look like this:


                  Dim pcbApp  'As MGCPCB.Application
                  Dim pcbDoc  'As MGCPCB.Document



                  Sub Main()

                      Scripting.AddTypeLibrary ("MGCPCB.Application")
                     Set pcbApp = Application  'In process can access the Application directly
                      Set pcbDoc = pcbApp.ActiveDocument

                  end Sub



                  I never publish scripts as .exe files.  They are slower, do not work on all platforms and they can be version or machine dependent.


                  The steps are included in the AATK release.  $AATK\help\LABS-Powerpoints\Automation_Lab.ppt and I have included the PPT here.



                  • 6. Re: A question about used defined type

                    I will second what Kendall is saying about VB6.  When I first started writing scripts for Expedition, I wrote all of them in VB6.  At the time I never knew about the performance hit you got with doing you scripts this way and I just accepted that the scripting engine just wasn't that fast.  Then one day (I was probably inspired by Kendall's AATK scripts), I rewrote one of my scripts to be a VBSCRIPT and I was amazed how much faster the scripts ran by running them inside of Expedition vs. externally with VB6.


                    If you already know VB6, moving to VBSCRIPTs really isn't that much of a change.

                    • 7. Re: A question about used defined type

                      Hello Kendall,

                         Thanks for your explanation and for the presentation file you have sent me.

                         I followed you instruction, and earlier today I wrote a  Vb6 sample program that works fine.

                         The next programs are going to be mutations of the  first one...


                                                                 Many thanks,



                      • 8. Re: A question about used defined type

                        Hello Jeff,

                           Thank you for your answer.

                           I  take into consideration your advices about choosing  coding language.

                           Speed is important but not yet, for me , since my programs in the near future are going to be small.

                           I prefare to use Vb6 because Vbscript uses a small font, which I hate.

                           Is there a way to harness another font to Vbscript inside Expedition ?

                           Another  reason: Over the years, I wrote many  useful "universal" subs and functions in Vb6.

                            Is there a way to use them in Vbscript ? ( except by copy-paste).


                                                          Best regards,








                        • 9. Re: A question about used defined type

                          1) Speed - I did some testing for a presentation I did at U2U in 2006 and I took basically the same code except one was a compiled VB6 program and the other was script ran internally.  What the program did was generate a AIS file like you would get when you do File->Export->General Interfaces->Generic AIS, except that it was specially formatted for our needs.  The VB6 program took around 10 seconds to run, compared to around a second for the  internally ran script.  This is a pretty small program.  I'm not sure if there is still that much of a performance differential between the two as this was an older version of Expedition.


                          2) Font Size - which fonts are you talking about?  With the editor?  Or with the output?


                          3) I think you will be stuck with copy and pasting unless Kendall has another method.




                          As far as editting vbscript files, I use an open source program called Notepad++ that works very well for me.  I sometimes also use VBSEdit which is probably a bit nicer, but it costs a little bit to register it.

                          • 10. Re: A question about used defined type

                            Here is how to change the font in the Script/Form editor and you don't have to put your script in a form to use it, you can call a *.vbs file from another method or drag and drop it on Expeition.  There are many examples of this in AATK.

                            The include function is in another recent thread.





                            • 11. Re: A question about used defined type

                              Hello Kendall,


                                 Thanks for your answer. I finally found where to change the font.

                                 I must confess, I did not open AATK yet.

                                 Before jumping into it I nust learn first the basics.

                                I did not know AATK has  also examples to learn from. I thought it is an add_in tool for Expedition Pcb, with additional functions.



                                                Thanks very much.