Drawing a simple line

Discussion in 'AutoCAD' started by Matthew Gonzalez, Aug 1, 2003.

  1. ok, I'm sure this is something really easy and I'll feel braindead once
    someone tells me what the problem is but here goes: I run this code and
    all variables get initialized perfect, everything seems to be going just
    dandy until the very end, I get no line. The Debug.Print line gives me
    this error: "Object variable or With block variable not set"

    Here's the relevant code:


    Dim objGridLine As AcadLine
    Dim varStart(2) As Variant
    Dim varEnd(2) As Variant
    Dim intI As Integer
    Dim varLength As Variant
    Dim int1 As Integer
    Dim varOffset As Variant

    varStart(0) = 0
    varStart(1) = 0
    varStart(2) = 0

    varOffset = ThisDrawing.GetVariable("dimscale") * 4

    ThisDrawing.ActiveLayer = ThisDrawing.Layers("S-GRID")

    If ThisDrawing.ActiveSpace = acPaperSpace Then
    ThisDrawing.ActiveSpace = acModelSpace
    End If

    If UCase(strDirection) = "VERT" Then
    int1 = 0
    varLength = 0
    For intI = LBound(varNumDims) To UBound(varNumDims)
    varLength = varLength + varNumDims(int1)
    int1 = int1 + 1
    Next intI

    varEnd(0) = 0
    varEnd(1) = varLength + varOffset
    varEnd(2) = 0
    End If


    Set objGridLine = ThisDrawing.ModelSpace.AddLine(varStart,
    varEnd)
    objGridLine.Update
    Debug.Print Err.Description


    Thanks.
     
    Matthew Gonzalez, Aug 1, 2003
    #1
  2. Does changing your Dim statements fix it?

    Dim varStart(2) As Double 'Variant
    Dim varEnd(2) As Double 'Variant

    HTH,
    James
     
    James Belshan, Aug 1, 2003
    #2
  3. Change all of your variable declarations that are defined as variants to doubles:

      Dim objGridLine As AcadLine   Dim varStart(2) As Double   Dim varEnd(2) As Double   Dim intI As Integer   Dim varLength As Double   Dim int1 As Integer   Dim varOffset As Double
     
    Mark_Abercrombie, Aug 1, 2003
    #3
  4. Change all of your variable declarations that are defined as variants
    (snip)

    That worked perfect, thanks. Now why did that work? Why does an array of
    variants need to be fed doubles?
     
    Matthew Gonzalez, Aug 1, 2003
    #4

  5. Yes, that worked, thanks. Why must they be doubles? I would think that
    variants would work fine since they are supposed to be more versatile.
     
    Matthew Gonzalez, Aug 1, 2003
    #5
  6. Nevermind, I changed to arrays to doubles too. But still, why do doubles
    work better than variants? Is there a rule that parameter somewhere that I
    didn't read about?
     
    Matthew Gonzalez, Aug 1, 2003
    #6
  7. (snip)
    (snip)

    It does work, thank you.
     
    Matthew Gonzalez, Aug 1, 2003
    #7
  8. Matthew Gonzalez

    Tom Craft Guest

    You can dimension the variable as a variant and it should work, but don't
    dimension it as an array of variants.
    dim startpoint as variant 'this should work
    startpoint(0) = x
    startpoint(1) = y
    startpoint(2) = z

    dim startpoint(0 to 2) as variant 'will not work

    Tom
     
    Tom Craft, Aug 7, 2003
    #8
  9. You can dimension the variable as a variant and it should work, but
    Hmmm... very curious. Thanks for the explanation.
     
    Matthew Gonzalez, Aug 7, 2003
    #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.