convert three doubles into variant

Discussion in 'AutoCAD' started by GLC, Apr 12, 2004.

  1. GLC

    GLC Guest

    How do I convert three variables that are doubles into a variant?

    I'm trying to create an autocad point using vba but my x,y,z values are are
    stored in seperate variables (for other purposes). How can I best combine
    them into a variant for use with the thisdrawing.modelspace.addpoint method?

    Thanks,
     
    GLC, Apr 12, 2004
    #1
  2. GLC

    Jeff Mishler Guest

    Dim myPoint(0 To 2) as Variant

    myPoint(0) = x : mypoint(1) = y : myPoint(2) = z
    thisdrawing.modelspace.addpoint myPoint

    HTH,
    Jeff
     
    Jeff Mishler, Apr 12, 2004
    #2
  3. GLC

    Mark Propst Guest

    I think it needs to be

    Dim myPoint(0 To 2) as Double
    then the rest will work
    I get an invalid proceedure call error trying to dim as variant
     
    Mark Propst, Apr 12, 2004
    #3
  4. GLC

    GLC Guest

    This works. Thanks, GLC


     
    GLC, Apr 12, 2004
    #4
  5. GLC

    Jeff Mishler Guest

    And I knew that, yet I typed it based on what the help says is required:
    Variant (three-element array of doubles); input-only
    The coordinates of the point to be created.

    One of these days I'll learn to check everything I post prior to
    posting.......



    Jeff
     
    Jeff Mishler, Apr 12, 2004
    #5
  6. GLC

    Mark Propst Guest

    I'm sure you know this but just in case,
    that is (uncharacteristically for help files) a correct statement

    your original statement
    Dim myPoint(0 To 2) as Variant
    creates an array of 3 variants
    not a variant containing an array of 3 doubles

    actually the help statement is "almost" correct since it accepted both an
    array of 3 doubles as well as accepting a Variant containing an array of 3
    doubles

    according to an extremely literal interpretation of the help statement I
    would expect an array of 3 doubles to fail but a variant containing an array
    of 3 doubles to succeed
    in fact they both work

    Sub test()
    Dim myPoint(0 To 2) As Double
    Dim myVar As Variant
    Dim x As Double, y As Double, z As Double

    myPoint(0) = x: myPoint(1) = y: myPoint(2) = z
    myVar = myPoint

    On Error Resume Next

    ThisDrawing.ModelSpace.AddPoint myPoint
    If Err Then
    Debug.Print "MyPoint didn't work"
    Else
    Debug.Print "MyPoint did work"
    End If

    ThisDrawing.ModelSpace.AddPoint myVar
    If Err Then
    Debug.Print "MyVar didn't work"
    Else
    Debug.Print "MyVar did work"
    End If
    End Sub
    'from immediate window
    MyPoint did work
    MyVar did work

    but then maybe I'm not understanding the difference between a variant and a
    variant containing an array of 3 doubles.
    ?
    :)
     
    Mark Propst, Apr 12, 2004
    #6
  7. GLC

    Jeff Mishler Guest

    Mark ended with:
    "but then maybe I'm not understanding the difference between a variant
    and a
    variant containing an array of 3 doubles.
    ?
    :)"

    Alas, therein lies MY problem and why I messed up the original post. I
    had assumed, incorrectly of course, that by dimensioning "myPoint" as a
    variant, then filling it with doubles, I would in turn get what was
    expected by "AddPoint".

    I've made this mistake in the past, and it appears that I'm refusing to
    learn from those mistakes......

    ;-(

    Thanks for setting me staright, once again......

    Jeff
     
    Jeff Mishler, Apr 12, 2004
    #7
  8. When passing an array of any type, VBA automatically wraps the array in a
    Variant for you. This is oe of those helpful little details that often
    causes confusion.
     
    Frank Oquendo, Apr 12, 2004
    #8
  9. GLC

    Mark Propst Guest

    Hi Frank,
    I suspected something like that, thanks for the explanation!
    Thanks,
    Mark
     
    Mark Propst, Apr 12, 2004
    #9
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.