-
Jan 3rd, 2013, 04:30 AM
#1
Thread Starter
New Member
Simple question from a noob...
Guys,
This is my first ever post, so go easy on me
I have a really basic VB script that simply picks up x,y,z coordinates from an excel spreadsheet and dumps it into AutoCAD to draw a polyline - that part works fine.
I have then added a line thickness and a colour - also working fine
But when I tried to add a line layer I get an error 'type mismatch' I assumed this was because I called it an integer so I changed it to string, but no joy
Any suggestions?
Option Explicit
Private Sub CommandButton1_Click()
Dim selRng As Range
Set selRng = Selection
Dim lineData As Variant
lineData = selRng.Value2
Dim acad As AcadApplication
Set acad = GetObject(, "Autocad.Application")
Dim adoc As AcadDocument
Set adoc = acad.ActiveDocument
Dim aspace As AcadBlock
Dim oSpline As AcadSpline
Set aspace = adoc.ActiveLayout.Block
Dim i As Integer
Dim p1(0 To 2) As Double
Dim p2(0 To 2) As Double
Dim lt As Double
Dim clr As Integer
Dim lay As Integer
For i = 1 To UBound(lineData, 1)
p1(0) = CDbl(lineData(i, 1)): p1(1) = CDbl(lineData(i, 2)): p1(2) = CDbl(lineData(i, 3))
p2(0) = CDbl(lineData(i, 4)): p2(1) = CDbl(lineData(i, 5)): p2(2) = CDbl(lineData(i, 6))
lt = CDbl(lineData(i, 7))
clr = CDbl(lineData(i, 8))
lay = CDbl(lineData(i, 9))
Dim oLine As AcadLine
Set oLine = aspace.AddLine(p1, p2)
oLine.Thickness = lt
oLine.Color = clr
oLine.Layer = lay
Next i
ZoomExtents
Set aspace = Nothing
Set adoc = Nothing
Set acad = Nothing
MsgBox "Successfully imported pipe network data"
End Sub
-
Jan 4th, 2013, 04:39 AM
#2
Re: Simple question from a noob...
lay = CDbl(lineData(i, 9))
as you are converting the value to a double, probably lay should also be a double, also clr
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jan 4th, 2013, 07:52 AM
#3
Re: Simple question from a noob...
A few thigns... 1) Welcome to the forums... 2) In the future, it helps if you do two things: a) if you're getting an error, point out the line where the error happens... don't just throw out a bunch of code and expect us to guess where the problem lies... b) use [code][/code] or [highlight][/highlight] tags around your code... this will preserve the indent and other formatting of the code that most of us find it easy to read the code. If you use the highlight option, you can also include the language, like this: [highlight=vb] or [highlight=vb.net] and so one... it tells the forum which color syntax to use... 3) In my signature is a link to the Hitchhiker's Guide to Getting Help... bookmark it, when you have some time, read it... it gives some hints on how to best get help around here. Hints range from how to title your posts ("simple question" doesn't tell anyone what the post is about and is likely to get skipped over... but "Getting a type mismatched error" helps better explain the situation and will attract more readers).
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|