Using a class to retrieve info from a CSV file.

Using a class to retrieve info from a CSV file.

Anonymous
Not applicable
314 Views
3 Replies
Message 1 of 4

Using a class to retrieve info from a CSV file.

Anonymous
Not applicable
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 LayerAttr >> Input #FileNo, La.Name, La.Color, La.LineType LayerInfoList.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
0 Likes
315 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
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 ??? "Dave F." wrote in message news:40a9dd51_3@newsprd01... > Hi > > >> Input #FileNo, La.Name, La.Color, La.LineType > LayerInfoList.Add La, La.Name > Set La = Nothing > Loop ' eof >
0 Likes
Message 3 of 4

Anonymous
Not applicable
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: Dim Lay As LayerBits Input #FileNo, Lay.LayNme, Lay.LayCol, Lay.LayLtp I think (hoping) there may be another solution (I can't stand defining Variables when they're not needed ) Cheers Dave F. "Mark Propst" wrote in message news:40a9fab9$1_1@newsprd01... > 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 > > ??? > > "Dave F." wrote in message news:40a9dd51_3@newsprd01... > > Hi > > > >> Input #FileNo, La.Name, La.Color, La.LineType > > LayerInfoList.Add La, La.Name > > Set La = Nothing > > Loop ' eof > > > >
0 Likes
Message 4 of 4

Anonymous
Not applicable
> And, I maybe I'm wrong here, but aren't UDT's & the class routine basically > the same thing? 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]
0 Likes