New to VBA

Discussion in 'AutoCAD' started by Kevin, Aug 27, 2004.

  1. Kevin

    Kevin Guest

    OK, I know I'm new to this and really making a big attempt to learn it but I
    am getting confused on a few things.

    1. I'm trying to create a routine to change layer, should be a simple thing
    to learn with, but I have the...
    Dim ss As IAcadSelectionSet
    Option Explicit

    Set ss = ThisDrawing.SelectionSets.Add("NEWSS")
    ss.SelectOnScreen

    in the Module1 (code) and I'm trying to do something with it in the
    UserForm1 (code).
    But it says it's not defined. Even though I defined it in the code before it
    gets to the point of stopping.

    Can you only set a variable to work in the (code) that you are referencing
    it in?

    I hope I'm making sense of this.

    2. Another problem I'm having is when I run this and it stops and then I try
    to run it again it's telling me...
    "The named select set exist" Can you create the code to clear the value of
    ss if you run it again?

    Kevin
     
    Kevin, Aug 27, 2004
    #1
  2. But it says it's not defined. Even though I defined it in the code before it
    You need to read up on Variable Scope. In extremely simple terms, if the
    module is calling the form, then you can use Public or Private to declare
    the variable and make it available to both. You can also pass it from place
    to place.
    When your program is done, issue a ss.Delete. It s also a good idea to
    check the selectionset collection of the drawing to make sure the name of
    the selection set is not already in use before you try using it.

    You should try going to your local library and signing out a copy of VBA
    For Dummies or some other such title. While its not AutoCAD related, it'll
    help get you up to speed on how VBA works. I like the library best so you
    don't have to make an initial investment - save that for a good AutoCAD VBA
    reference book =)

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 27, 2004
    #2
  3. Kevin

    Tim Badger Guest

    Kevin, look into the acad help file. Here you will find the "ActiveX and
    VBA Reference" section. From there look in the "Code Examples" section.
    There is a wealth of information there.
     
    Tim Badger, Aug 27, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.