Error type missmatch

Error type missmatch

Anonymous
Not applicable
742 Views
9 Replies
Message 1 of 10

Error type missmatch

Anonymous
Not applicable
I took a code right from a book for programming AutoCAD via vba, an error is given as a type missmatch in the line highlighted , any ideas ??
dim nbp as integer
For nbp = 0 To Val(Type_rad_form.TextBox1.Text) Step nbp + 1
MsgBox "SVP, choisir le chemin correspondant pour la tuyauterie du radiateur, " & nbp + 1 & vbNewLine & "(Uilisez un polyline)"

Dim objent As AcadLWPolyline
Dim dblnew() As Double
Dim lnglastvertex As Long
Dim varpick1, varpick2, varwcs As Variant
Dim varpick As Variant

ThisDrawing.SetVariable "ORTHOMODE", 1

With ThisDrawing.Utility

varpick1 = .GetPoint(, "Point 1 :")
varpick2 = .GetPoint(, "Point 2 :")
varpick2(0) = varpick1(0)
ReDim dblnew(0 To 3)
dblnew(0) = varpick1(0): dblnew(1) = varpick1(1)
dblnew(2) = varpick2(0): dblnew(3) = varpick2(1)
''obent = .GetEntity(,varpick,
If ThisDrawing.ActiveSpace = acModelSpace Then
Set objent = ThisDrawing.ModelSpace.AddLightWeightPolyline(dblnew)
Else
Set objent = ThisDrawing.PaperSpace.AddLightWeightPolyline(dblnew)
End If

objent.Update

''If objEnt Is Nothing Then Exit Sub
'' exit if not a lwpolyline
''/////So far everythinggoes well ////////"
'' copy last vertex of pline into pickpoint to begin loop
''/////////////////////////////////////////////////////////////////// the next line gives the error while double can be assigned to variant ????
''/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
''/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
varpick(0) = objent.Coordinates(UBound(objent.Coordinates) - 1)
varpick(1) = objent.Coordinates(UBound(objent.Coordinates))
varpick(2) = 0
'' append vertexes in a loop
Do
'' translate picked point to UCS for basepoint below
varwcs = .TranslateCoordinates(varpick, acWorld, acUCS, True)
'' get user point for new vertex, use last pick as basepoint
varpick = .GetPoint(varwcs, vbCr & "Pick another point : ")
'' exit loop if no point picked
If Err Then Exit Do
'' copy picked point X and Y into new 2d point
dblnew(0) = varpick(0): dblnew(1) = varpick(1)
'' get last vertex offset. it is one half the array size
lnglastvertex = (UBound(objent.Coordinates) + 1) / 2
'' add new vertex to pline at last offset
objent.AddVertex lnglastvertex, dblnew
Loop
End With
objent.Update
0 Likes
743 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

Man I wish they'd hurry up and get this forum
software fixed so I could actually read these posts.....

 

A few things.....

This:

Dim varpick1, varpick2, varwcs As Variant

isn't doing what you think it is (well, it IS in
THIS case ending up that way, but usually it won't). Dim'ing a number variables
like this does NOT set them all to be what the AS specifies in VBA. Each one
must have it's own AS or they will default to the Variant type.

 

Now for why your code fails....

When you Dim the varpick variable as a variant, the
code does not know you really wanted a Variant Array. Change that to Dim
varpick(2) as Variant and it should work ok

 

HTH

 


style="BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px">
I
took a code right from a book for programming AutoCAD via vba, an error is
given as a type missmatch in the line highlighted , any ideas ?? dim nbp as
integer For nbp = 0 To Val(Type_rad_form.TextBox1.Text) Step nbp + 1 MsgBox
"SVP, choisir le chemin correspondant pour la tuyauterie du radiateur, " &
nbp + 1 & vbNewLine & "(Uilisez un polyline)" Dim objent As
AcadLWPolyline Dim dblnew() As Double Dim lnglastvertex As Long Dim varpick1,
varpick2, varwcs As Variant Dim varpick As Variant ThisDrawing.SetVariable
"ORTHOMODE", 1 With ThisDrawing.Utility varpick1 = .GetPoint(, "Point 1 :")
varpick2 = .GetPoint(, "Point 2 :") varpick2(0) = varpick1(0) ReDim dblnew(0
To 3) dblnew(0) = varpick1(0): dblnew(1) = varpick1(1) dblnew(2) =
varpick2(0): dblnew(3) = varpick2(1) ''obent = .GetEntity(,varpick, If
ThisDrawing.ActiveSpace = acModelSpace Then Set objent =
ThisDrawing.ModelSpace.AddLightWeightPolyline(dblnew) Else Set objent =
ThisDrawing.PaperSpace.AddLightWeightPolyline(dblnew) End If objent.Update
''If objEnt Is Nothing Then Exit Sub '' exit if not a lwpolyline ''/////So far
everythinggoes well ////////" '' copy last vertex of pline into pickpoint to
begin loop
''/////////////////////////////////////////////////////////////////// the next
line gives the error while double can be assigned to variant ????
''/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
''/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
varpick(0) = objent.Coordinates(UBound(objent.Coordinates) - 1) varpick(1) =
objent.Coordinates(UBound(objent.Coordinates)) varpick(2) = 0 '' append
vertexes in a loop Do '' translate picked point to UCS for basepoint below
varwcs = .TranslateCoordinates(varpick, acWorld, acUCS, True) '' get user
point for new vertex, use last pick as basepoint varpick = .GetPoint(varwcs,
vbCr & "Pick another point : ") '' exit loop if no point picked If
Err Then Exit Do '' copy picked point X and Y into new 2d point dblnew(0) =
varpick(0): dblnew(1) = varpick(1) '' get last vertex offset. it is one half
the array size lnglastvertex = (UBound(objent.Coordinates) + 1) / 2 '' add new
vertex to pline at last offset objent.AddVertex lnglastvertex, dblnew Loop End
With objent.Update
0 Likes
Message 3 of 10

Anonymous
Not applicable
Hi Jeff,

The latest news I have (from last week) is that they acknowledge there
is a problem and they are talking to their service supplier to see if
may be they can have a planning session which will see if they should
think about coming up with a plan to see if the plan will be feasible if
able to be implemented in the fullness of time.

I think it's time to start writing to Carl Bass again.


Regards,


Laurie Comerford

ps - I'm sorry my gobble-de-gook is almost comprehensible. I struggle
to fit myself into their mindset. 😞

Jeff Mishler wrote:
> Man I wish they'd hurry up and get this forum software fixed so I could
> actually read these posts.....
>
> A few things.....
> This:
> Dim varpick1, varpick2, varwcs As Variant
> isn't doing what you think it is (well, it IS in THIS case ending up
> that way, but usually it won't). Dim'ing a number variables like this
> does NOT set them all to be what the AS specifies in VBA. Each one must
> have it's own AS or they will default to the Variant type.
>
> Now for why your code fails....
> When you Dim the varpick variable as a variant, the code does not know
> you really wanted a Variant Array. Change that to Dim varpick(2) as
> Variant and it should work ok
>
> HTH
>
>
> "Elie911" wrote in message news:6203160@discussion.autodesk.com...
> I took a code right from a book for programming AutoCAD via vba, an
> error is given as a type missmatch in the line highlighted , any
> ideas ?? dim nbp as integer For nbp = 0 To
> Val(Type_rad_form.TextBox1.Text) Step nbp + 1 MsgBox "SVP, choisir
> le chemin correspondant pour la tuyauterie du radiateur, " & nbp + 1
> & vbNewLine & "(Uilisez un polyline)" Dim objent As AcadLWPolyline
> Dim dblnew() As Double Dim lnglastvertex As Long Dim varpick1,
> varpick2, varwcs As Variant Dim varpick As Variant
> ThisDrawing.SetVariable "ORTHOMODE", 1 With ThisDrawing.Utility
> varpick1 = .GetPoint(, "Point 1 :") varpick2 = .GetPoint(, "Point 2
> :") varpick2(0) = varpick1(0) ReDim dblnew(0 To 3) dblnew(0) =
> varpick1(0): dblnew(1) = varpick1(1) dblnew(2) = varpick2(0):
> dblnew(3) = varpick2(1) ''obent = .GetEntity(,varpick, If
> ThisDrawing.ActiveSpace = acModelSpace Then Set objent =
> ThisDrawing.ModelSpace.AddLightWeightPolyline(dblnew) Else Set
> objent = ThisDrawing.PaperSpace.AddLightWeightPolyline(dblnew) End
> If objent.Update ''If objEnt Is Nothing Then Exit Sub '' exit if not
> a lwpolyline ''/////So far everythinggoes well ////////" '' copy
> last vertex of pline into pickpoint to begin loop
> ''///////////////////////////////////////////////////////////////////
> the next line gives the error while double can be assigned to
> variant ????
> ''/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> ''/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> varpick(0) = objent.Coordinates(UBound(objent.Coordinates) - 1)
> varpick(1) = objent.Coordinates(UBound(objent.Coordinates))
> varpick(2) = 0 '' append vertexes in a loop Do '' translate picked
> point to UCS for basepoint below varwcs =
> .TranslateCoordinates(varpick, acWorld, acUCS, True) '' get user
> point for new vertex, use last pick as basepoint varpick =
> .GetPoint(varwcs, vbCr & "Pick another point : ") '' exit loop if no
> point picked If Err Then Exit Do '' copy picked point X and Y into
> new 2d point dblnew(0) = varpick(0): dblnew(1) = varpick(1) '' get
> last vertex offset. it is one half the array size lnglastvertex =
> (UBound(objent.Coordinates) + 1) / 2 '' add new vertex to pline at
> last offset objent.AddVertex lnglastvertex, dblnew Loop End With
> objent.Update
>
0 Likes
Message 4 of 10

Anonymous
Not applicable


Hi Jeff,



Thank you for your reply.



I use varpick in the GetPoint method which don't accept an array.

I also tried it but as mensioned, the error occurs : Can't assign to array





Any ideas ??

0 Likes
Message 5 of 10

Anonymous
Not applicable

Hi Elie,

The only place in the code, as best I can decipher
it due to the line breaks being stripped out, is here:

 

    With
ThisDrawing.Utility
        varpick1 =
.GetPoint(, "Point 1 :")
        varpick2
= .GetPoint(, "Point 2 :")
       
varpick2(0) = varpick1(0)
        ReDim
dblnew(0 To 3)
        dblnew(0) =
varpick1(0): dblnew(1) =
varpick1(1)
        dblnew(2) =
varpick2(0): dblnew(3) =
varpick2(1)
        ''obent =
.GetEntity(,varpick,   
<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       
If ThisDrawing.ActiveSpace = acModelSpace
Then
            Set
objent =
ThisDrawing.ModelSpace.AddLightWeightPolyline(dblnew)
       
Else

 

which is in a commented section of code, until you
try to assign it here:

       
varpick(0) = objent.Coordinates(UBound(objent.Coordinates) -
1)
        varpick(1) =
objent.Coordinates(UBound(objent.Coordinates))
       
varpick(2) = 0

But since it has not yet been used as an array, it
is erroring on you.


style="BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"
dir=ltr>


Hi Jeff,




Thank you for your reply.




I use varpick in the GetPoint method which don't accept an
array.

I also tried it but as mensioned, the error occurs : Can't
assign to array






Any ideas ??

0 Likes
Message 6 of 10

Anonymous
Not applicable
Yeah, I was informed of roughly the same thing about a month ago.

Me thinks their "service supplier" needs to be fired.

"Laurie" wrote in message
news:6203631@discussion.autodesk.com...
> Hi Jeff,
>
> The latest news I have (from last week) is that they acknowledge there
> is a problem and they are talking to their service supplier to see if
> may be they can have a planning session which will see if they should
> think about coming up with a plan to see if the plan will be feasible if
> able to be implemented in the fullness of time.
>
> I think it's time to start writing to Carl Bass again.
>
>
> Regards,
>
>
> Laurie Comerford
>
> ps - I'm sorry my gobble-de-gook is almost comprehensible. I struggle
> to fit myself into their mindset. 😞
0 Likes
Message 7 of 10

Anonymous
Not applicable
Please can someone help me .

I have been working on this for 3 days and no result.

I need to add a polyline to the modelspace like this : get 2 point from the user for the first vertex, then get point by point until he presses Esc.

This code is giving an error "Invalid procedure call or argument" on the line where I add the LightWeightPolyline .



The code is :



Dim nbp as integer

Dim objent As AcadLWPolyline

Dim dblnew() As Double

Dim lnglastvertex As Long

Dim varpick1, varpick2, varwcs As Variant

Dim varpick As Variant



ThisDrawing.SetVariable "ORTHOMODE", 1



For nbp = 0 To Val(Type_rad_form.TextBox1.Text) Step nbp + 1

MsgBox "SVP, choisir le chemin correspondant pour la tuyauterie du radiateur, " & nbp + 1 & vbNewLine & "(Uilisez un polyline)"




With ThisDrawing.Utility



pt1 = .GetPoint(, "Premier point :")

pt2 = .GetPoint(pt1, "Second point :")





var(0) = CVar(pt1(0))

var(1) = CVar(pt1(1))

var(2) = CVar(pt2(0))

var(3) = CVar(pt2(1))



End With





If ThisDrawing.ActiveSpace = acModelSpace Then

''///////////////////////////////////////error/////////////////////////////////////////

Set objEnt = ThisDrawing.ModelSpace.AddLightWeightPolyline(var)



Else

Set objEnt = ThisDrawing.PaperSpace.AddLightWeightPolyline(var)



End If



objEnt.Closed = True

objEnt.Update





'' copy last vertex of pline into pickpoint to begin loop

ReDim varpick(2)

varpick(0) = objEnt.Coordinates(UBound(objEnt.Coordinates) - 1)

varpick(1) = objEnt.Coordinates(UBound(objEnt.Coordinates))

varpick(2) = 0



'' append vertexes in a loop

Do



'' translate picked point to UCS for basepoint below

varwcs = ThisDrawing.Utility.TranslateCoordinates(varpick, acWorld, acUCS, True)



'' get user point for new vertex, use last pick as basepoint

varpick = ThisDrawing.Utility.GetPoint(varwcs, vbCr & "Pick another point <exit>: ")



'' exit loop if no point picked

If Err Then Exit Do



'' copy picked point X and Y into new 2d point

dblnew(0) = varpick(0): dblnew(1) = varpick(1)



'' get last vertex offset. it is one half the array size

lnglastvertex = (UBound(objEnt.Coordinates) + 1) / 2



'' add new vertex to pline at last offset

objEnt.AddVertex lnglastvertex, dblnew

Loop



objEnt.Update

Next

0 Likes
Message 8 of 10

Anonymous
Not applicable

Give this a try Elie. I reordered some of you code
and added some Dim's.

 

{code}

Option Explicit

 

Sub testme()
Dim nbp As Integer

 

Dim objent As AcadLWPolyline

 

Dim dblnew(1) As Double

 

Dim lnglastvertex As Long

 

Dim varpick1, varpick2, varwcs As
Variant

 

Dim varpick As Variant

 

 

 

ThisDrawing.SetVariable "ORTHOMODE", 1

 

 

 

For nbp = 0 To 2 Step 1

 

MsgBox "SVP, choisir le chemin correspondant pour
la tuyauterie du radiateur, " & nbp + 1 & vbNewLine & "(Uilisez un
polyline)"

 

 

 

 

 

With ThisDrawing.Utility

 

Dim pt1 As Variant
Dim pt2 As
Variant

 

pt1 = .GetPoint(, "Premier point :")

 

pt2 = .GetPoint(pt1, "Second point :")

 


Dim var(3) As Double

 

 

 


var(0) = CVar(pt1(0))

 

var(1) = CVar(pt1(1))

 

var(2) = CVar(pt2(0))

 

var(3) = CVar(pt2(1))

 

 

 

End With

 

 

 

 

 

 

 

If ThisDrawing.ActiveSpace = acModelSpace Then

 

''///////////////////////////////////////error/////////////////////////////////////////

 

Set objent = ThisDrawing.ModelSpace.AddLightWeightPolyline(var)

 

 

 

Else

 

Set objent = ThisDrawing.PaperSpace.AddLightWeightPolyline(var)

 

 

 

End If

 

 

 

objent.Closed = True

 

objent.Update

 

 

 


Do

 

 

 

'' copy last vertex of pline into pickpoint to begin loop

 

Dim lastPt(2) As Double

 

lastPt(0) = objent.Coordinates(UBound(objent.Coordinates) - 1)

 

lastPt(1) = objent.Coordinates(UBound(objent.Coordinates))

 

lastPt(2) = 0

 

 

 

'' append vertexes in a loop

 

 

 


'' translate picked point to UCS for basepoint below

 

varwcs = ThisDrawing.Utility.TranslateCoordinates(lastPt, acWorld, acUCS,
True)

 


On Error Resume Next
'' get user point for new vertex, use last pick
as basepoint

 

varpick = ThisDrawing.Utility.GetPoint(varwcs, vbCr & "Pick another
point <exit>: ")

 

 

 

'' exit loop if no point picked

 

If Err Then Exit Do

 

On Error GoTo 0

 

'' copy picked point X and Y into new 2d point

 

dblnew(0) = varpick(0): dblnew(1) = varpick(1)

 

 

 

'' get last vertex offset. it is one half the array size

 

lnglastvertex = (UBound(objent.Coordinates) + 1) / 2

 

 

 

'' add new vertex to pline at last offset

 

objent.AddVertex lnglastvertex, dblnew

 

Loop

 

 

 

 

 

objent.Update

 

Next

 


End Sub
{/code}


style="BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"
dir=ltr>
Please
can someone help me .

I have been working on this for 3 days and no
result.

I need to add a polyline to the modelspace like this : get 2
point from the user for the first vertex, then get point by point until he
presses Esc.

This code is giving an error "Invalid procedure call or
argument" on the line where I add the LightWeightPolyline .

 

0 Likes
Message 9 of 10

Anonymous
Not applicable

Why convert Double to Variant and then assign it to
a variable of Double type?

 

var(0) = CVar(pt1(0))

var(1) = CVar(pt1(1))

var(2) =
CVar(pt2(0))

var(3) = CVar(pt2(1))

 

It should be as simple as

 

var(0) = pt1(0)

var(1) = pt1(1)

var(2) = pt2(0)

var(3)
= pt2(1)

 

Of course, it is assumed you correctly declared var
as an array of Double somewhere before these lines of code (you did not show the
declaration in your code), like this:

 

Dim var(0 to 3) As Double

 

It is very likely you declared it this
way:

 

Dim var(0 to 3) As Variant

 

If so, you would get that error for sure, because
the argument of "AddLightWeightPolyline()"
method expects an array of Double, not an array of Variant.

 

 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Please
can someone help me .

I have been working on this for 3 days and no
result.

I need to add a polyline to the modelspace like this : get 2
point from the user for the first vertex, then get point by point until he
presses Esc.

This code is giving an error "Invalid procedure call or
argument" on the line where I add the LightWeightPolyline .



The
code is :



Dim nbp as integer

Dim objent As
AcadLWPolyline

Dim dblnew() As Double

Dim lnglastvertex As
Long

Dim varpick1, varpick2, varwcs As Variant

Dim varpick As
Variant



ThisDrawing.SetVariable "ORTHOMODE",
1



For nbp = 0 To Val(Type_rad_form.TextBox1.Text) Step nbp +
1

MsgBox "SVP, choisir le chemin correspondant pour la tuyauterie du
radiateur, " & nbp + 1 & vbNewLine & "(Uilisez un
polyline)"





With ThisDrawing.Utility



pt1 = .GetPoint(, "Premier
point :")

pt2 = .GetPoint(pt1, "Second point :")






var(0) = CVar(pt1(0))

var(1) =
CVar(pt1(1))

var(2) = CVar(pt2(0))

var(3) = CVar(pt2(1))


 






End With






If ThisDrawing.ActiveSpace = acModelSpace
Then

''///////////////////////////////////////error/////////////////////////////////////////

Set
objEnt =
ThisDrawing.ModelSpace.AddLightWeightPolyline(var)



Else

Set
objEnt = ThisDrawing.PaperSpace.AddLightWeightPolyline(var)



End
If



objEnt.Closed = True

objEnt.Update






'' copy last vertex of pline into pickpoint to begin
loop

ReDim varpick(2)

varpick(0) =
objEnt.Coordinates(UBound(objEnt.Coordinates) - 1)

varpick(1) =
objEnt.Coordinates(UBound(objEnt.Coordinates))

varpick(2) =
0



'' append vertexes in a loop

Do



''
translate picked point to UCS for basepoint below

varwcs =
ThisDrawing.Utility.TranslateCoordinates(varpick, acWorld, acUCS,
True)



'' get user point for new vertex, use last pick as
basepoint

varpick = ThisDrawing.Utility.GetPoint(varwcs, vbCr &
"Pick another point <exit>: ")



'' exit loop if no point
picked

If Err Then Exit Do



'' copy picked point X and Y
into new 2d point

dblnew(0) = varpick(0): dblnew(1) =
varpick(1)



'' get last vertex offset. it is one half the array
size

lnglastvertex = (UBound(objEnt.Coordinates) + 1) /
2



'' add new vertex to pline at last
offset

objEnt.AddVertex lnglastvertex, dblnew

Loop




objEnt.Update

Next

0 Likes
Message 10 of 10

Anonymous
Not applicable


Now I corrected as you mentioned and another error is appearing from the line :



varwcs = ThisDrawing.Utility.TranslateCoordinates(varpick, acWorld, acUCS, True)



"Invalid Argument point in TranslateCoordinates"



Looking on the varpick elements, everything seems to be normal .

Any ideas ???



Regards ...
0 Likes