Using a class to retrieve info from a CSV file.

Discussion in 'AutoCAD' started by Dave F., May 18, 2004.

  1. Dave F.

    Dave F. Guest

    Hi

    Following on from the great help I had from Bobby C. Jones, I'm getting this
    problem:

    The >> line is highlighting La.Name & giving the error:

    Variable required - can't assign to this expression.

    I've tested La.Name by putting a value into it & I've retrieved it
    successfully, so the Class appears to be working OK.

    I've looked in the help & this might be the problem, but I don't know how
    to solve it:

    "You used a function call or an expression as an argument to Input #, Let,
    Get, or Put. For example, you may have used an argument that appears to be a
    valid reference to an array variable, but instead is a call to a function of
    the same name".

    I've checked for functions called La - there aren't any.

    Any ideas?

    TIA
    Dave F.

    Sub UserForm_Initialize()
    Dim FileNo As Integer
    Dim La As LayerAttr
    Dim LayerInfoList As Collection

    Set LayerInfoList = New Collection
    FileNo = FreeFile

    Open "c:\dwgs\fx15\fxlayersCSV.txt" For Input As FileNo

    Do While Not EOF(FileNo)
    Set La = New LayerAttrLayerInfoList.Add La, La.Name
    Set La = Nothing
    Loop ' eof

    Close FileNo
    End Sub

    ------------------------
    This is the Class module named LayerAttr
    ------------------------
    Option Explicit

    Private m_Name As String
    Private m_Color As String
    Private m_LineType As String

    Public Property Get Name() As String
    Name = m_Name
    End Property

    Public Property Let Name(newName As String)
    m_Name = newName
    End Property

    Public Property Get Color() As String
    Color = m_Color
    End Property

    Public Property Let Color(newColor As String)
    m_Color = newColor
    End Property

    Public Property Get LineType() As String
    LineType = m_LineType
    End Property

    Public Property Let LineType(newLineType As String)
    m_LineType = newLineType
    End Property
     
    Dave F., May 18, 2004
    #1
  2. Dave F.

    Mark Propst Guest

    from the msdn

    The Input # statement syntax has these parts:

    Part Description
    filenumber Required. Any valid file number.
    varlist Required. Comma-delimited list of variables that are assigned
    values read from the file - can't be an array or object variable. However,
    variables that describe an element of an array or user-defined type may be
    used.

    your var list is a list of object properties
    maybe try
    Dim sName as string
    Dim sColor as string
    Dim sLineType as str

    Input #FileNo, sName, sColor, sLineType

    La.Name = sname
    La.Color = scolor
    La.LineType = slinetype
    etc

    ???
     
    Mark Propst, May 18, 2004
    #2
  3. Dave F.

    Dave F. Guest

    Mark

    Thanks, that does make it work but...

    I'm confused. Because user defined types (UDT) work.
    And, I maybe I'm wrong here, but aren't UDT's & the class routine basically
    the same thing?

    UDT defined in declaration area of module:

    Type LayerBits
    LayNme As String
    LayCol As String
    LayLtp As String
    End Type

    Form object:

    <snip>
    Dim Lay As LayerBits
    Input #FileNo, Lay.LayNme, Lay.LayCol, Lay.LayLtp
    <snip>

    I think (hoping) there may be another solution (I can't stand defining
    Variables when they're not needed <g>)

    Cheers
    Dave F.
     
    Dave F., May 18, 2004
    #3
  4. And, I maybe I'm wrong here, but aren't UDT's & the class routine basically
    No UDTs are your own datatypes and classes are your own objects. The INPUT
    command requires variables not properties as arguments. If you use a class,
    it has properties since it is an object, and you get the error message.

    I'm not even sure you should be using a class because you are not defining
    anything new or different to the basic AutoCAD Layer object. What you need
    to do, probably, is create a scripting dictionary object that stores the
    comma-delimited data and uses the Name as the key. Then you search on the
    key and SPLIT the contents apart as needed.

    Also you might want to look at reading your text file in as a stream
    instead of one line at a time - dpending upon how many lines you are
    writing. Best method is still XML but I apologize for not having time to
    post a demo that fully shows you how to accomplish what you want. [I did
    post a mini to get you started, tho]
     
    Mike Tuersley, May 18, 2004
    #4
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.