building a list from scanned TextNodeElements

What is wrong with my code?

Sub EE_Example()
Dim ee As ElementEnumerator
Dim es As New ElementScanCriteria
Dim elArray() As Element
Dim i As Long
Dim iStart As Long
Dim iEnd As Long
Dim elLevel As Level
Dim elVariant() As Variant
Dim bigString As String

'
' set element scan criteria to find only described elements
'

Set elLevel = ActiveDesignFile.Levels("DRAWING TEXT")

es.ExcludeAllColors
es.IncludeColor 7
es.ExcludeAllLevels
es.IncludeLevel elLevel
es.ExcludeAllTypes
es.IncludeType msdElementTypeTextNode

'
' set enumerator from active model
'
Set ee = ActiveModelReference.Scan(es)

'
' get an element array of all elements found
'
elArray = ee.BuildArrayFromContents
iStart = LBound(elArray)
iEnd = UBound(elArray)

'
' loop through array and get the second line of text
'
For i = iStart To iEnd
elVariant(i) = elArray(i).AsTextNodeElement.TextLine(2)
bigString = Join(elVariant(i), ",")
Next


End Sub

Parents
  • Reu,

    You don't say what your code is doing wrong. So we are left to speculate. I don't have access to MicroStation on the computer I typing this response on so I can't test it out now but a few things pop out at me

    1. elVariant() is dimensioned as a Variant but it contains string values. Change the type to String. 
      Dim elVariant() as String 
       
    2. The value of bigString is being set to the last value of elVariant plus a ",". You probably want the value of bigString to be a concatenation of all of the text node lines.
       bigString = bigString & elVariant(i) & ","
       
    3. You need to set an error check if you encounter a text node that only has one line.
       
    4. At the end of the sub the last character in the bigString variable will be a comma (,) which is probably not what you want. Use the Len and Left$ functions to strip off the last character
      bigString = Left$(bigString,Len(bigString)-1)
    Hopefully this will solve some of the problems you are having.
    Rod

    Rod Wing
    Senior Systems Analyst

    Answer Verified By: rashil 

Reply
  • Reu,

    You don't say what your code is doing wrong. So we are left to speculate. I don't have access to MicroStation on the computer I typing this response on so I can't test it out now but a few things pop out at me

    1. elVariant() is dimensioned as a Variant but it contains string values. Change the type to String. 
      Dim elVariant() as String 
       
    2. The value of bigString is being set to the last value of elVariant plus a ",". You probably want the value of bigString to be a concatenation of all of the text node lines.
       bigString = bigString & elVariant(i) & ","
       
    3. You need to set an error check if you encounter a text node that only has one line.
       
    4. At the end of the sub the last character in the bigString variable will be a comma (,) which is probably not what you want. Use the Len and Left$ functions to strip off the last character
      bigString = Left$(bigString,Len(bigString)-1)
    Hopefully this will solve some of the problems you are having.
    Rod

    Rod Wing
    Senior Systems Analyst

    Answer Verified By: rashil 

Children
No Data