.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

String Array Problems

3 REPLIES 3
Reply
Message 1 of 4
Rob.O
335 Views, 3 Replies

String Array Problems

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!

3 REPLIES 3
Message 2 of 4
arcticad
in reply to: Rob.O

   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

 

---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 3 of 4
Hallex
in reply to: Rob.O

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(){})

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 4 of 4
chiefbraincloud
in reply to: Rob.O

Yeah, much better to use a List(of String) or a StringCollection, both of which have an Add method and automatically size themselves.

Dave O.                                                                  Sig-Logos32.png

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost