Results 1 to 3 of 3

Thread: Simple question from a noob...

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2013
    Posts
    1

    Talking 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

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,522

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width