VBA/VB Question - Variables

Discussion in 'AutoCAD' started by DRW1975, Feb 15, 2005.

  1. DRW1975

    DRW1975 Guest

    I have set up a global variable called VarCoords() as variant. As I am currently using it, it takes on the dimensions VarCoords(X,Y) where X ranges from 0 to n (some number of points), and Y ranges from 0 to 6. Right now, I want to expand my program and basically turn one of the x,y entries into a set of values of size m (to be determined later) in the same way one of my variables (X,1) is a 3D coordinate which information can be obtained by going VarCoords(X,1)(0) for x coordinate or (1) for y coordinate or (2) for z coordinate. Is there a way to tell VBA that my entry VarCoords(X,6) is to have 'm' entries which can be populated or retrieved by doing VarCoords(X,6)(0) or (1) or ... (m) ??

    or to do this will I have to use a user-defines data type defined something like this

    type VarCoords(n)
    Var1 as integer
    Var2(2) as double
    ...
    Var6(m) as double
    end type

    ???
    I didn't want to bother with user types in the beginning, but as my program evolves, it is getting more complicated with more variables - and I may have to go this route.

    thanks

    DRW
     
    DRW1975, Feb 15, 2005
    #1
  2. DRW1975

    DRW1975 Guest

    I've just noticed that a user type variable cannot be global.... is that right? - how can I pass it from one form to another?

    As well, it seems I cannot set an array against the main variable itself, and will have to set arrays against each entry

    type VarCoords
    Var1(n) as integer
    Var2(n) as variant
    ...
    Var6(n,m) as double
    end type

    is that right?

    Will that cause difficulties if i am trying to set a variable to an ACAD coordinate like

    VarCoords.Var2(n) = pt1 -> where pt1 is a x,y,z coordinate of a point in model space
     
    DRW1975, Feb 15, 2005
    #2
  3. DRW1975

    VBA Guest

    Sounds to me like you need to learn to deal with classes and objects.
     
    VBA, Feb 15, 2005
    #3
  4. DRW1975

    DRW1975 Guest

    Probably a fair statement, i've never been formally trained in either ACAD or VBA, just picking it up from books or playing around with it.
    I will read up on it.

    thanks
     
    DRW1975, Feb 16, 2005
    #4
  5. I've just noticed that a user type variable cannot be global.... is that
    'One way is to dim your variables in ThisDrawing
    'Double Click in Project Window
    '<ThisDrawing>
    Option Explicit
    Public stringTest As String
    '</ThisDrawing>

    'Now add a module and test.
    <Module1>
    Sub Test()
    ThisDrawing.stringTest = "Nicky"
    Debug.Print ThisDrawing.stringTest
    End Sub
    </Module1>


    'Better way is to make variables private in a class
    'and and then use properties to set and retrive. You
    'could add data validation here also;

    'Add a Class to a project "Class1" and
    'paste in the following code

    '<Class1>
    Option Explicit

    Private stringTest As String

    Public Property Get GetStringTest() As String
    GetStringTest = stringTest
    End Property

    Public Property Let GetStringTest(ByVal vNewValue As String)
    stringTest = vNewValue
    End Property
    '</Class1>

    'Test stub..

    '<Module1>
    Sub TestWithClass()

    Dim stringTest As New Class1

    stringTest.GetStringTest = ("Nicky")

    Debug.Print stringTest.GetStringTest

    Set stringTest = Nothing

    End Sub
    '</Module1>

    gl

    Paul
     
    Paul Richardson, Feb 16, 2005
    #5
  6.  
    Paul Richardson, Feb 16, 2005
    #6
  7. DRW1975

    DRW1975 Guest

    Ok, I'm trying out the whole class module thing, and I have your little example working (thanks!). But now I am trying to see how I can apply this to my particular problem... I'm sure i'll have some follow up questions as I struggle my way to an answer.

    DRW
     
    DRW1975, Feb 17, 2005
    #7
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.