Can someone please help me with my bad programing?
I am having a serious brain fart today (it's been a long day). I need to get the values(textstrings) of some AutoCAD table cells into a string array, but I am having troubles. I have the proper table and I can get the contents of individual cells using acTable.Cells(1, 1).TextString, etc... but I cannot seem to remember how to get each cell value into an array.
See code below:
For Each acCell As Cell In acTable If acCell.TextString > Nothing Then strArray() = acCell.TextString 'Does not work End If Next
Thanks for any help you can provide!
For Each acCell As Cell In acTable If acCell.TextString > Nothing Then ' increment array by 1 inc(strArray) ' Append to End strArray(UBound(strArray)) = acCell.TextString End If Next Function isValid(ByRef myarray() As String) As Boolean Try For Each item As Object In myarray isValid = True Exit Function Next Catch ex As Exception Return False End Try End Function Function inc(ByRef myarray() As String) If isValid(myarray) Then ReDim Preserve myarray(UBound(myarray) + 1) Else ReDim myarray(0) End If Return myarray End Function
Another way, not tested though
Public Sub FillArray()
Dim ptArray(,) As String = Nothing'<-- declare empty array
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database= doc.Database
Dim ed As Editor= doc.Editor
Dim tr As Transaction= doc.TransactionManager.StartTransaction
Dim pr As PromptEntityResult = ed.GetEntity("Select table : ")
If pr.Status <> PromptStatus.OK ThenReturnUsingtr
Dim ent As Entity = DirectCast(tr.GetObject(pr.ObjectId, OpenMode.ForRead), Entity)
Dim table As Table = TryCast(ent, Table)
If table Is Nothing Then Return'create array of string instance with two dimension lengs
ptArray = _
Array.CreateInstance(GetType(String), table.NumRows, table.NumColumns)
For row AsInteger = 0 To table.NumRows - 1
For col AsInteger = 0 To table.NumColumns - 1
ptArray(row, col) = table.TextString(row, col)
Next
Next
End Using
End Sub
But better yet to use
Dim ptArray as List(of List(of String))=new List(of string)(new String(){})
Yeah, much better to use a List(of String) or a StringCollection, both of which have an Add method and automatically size themselves.