Forum Discussion

longm's avatar
longm
New Contributor
13 years ago

Attempting to get a count of an array/object

Code:


Message = MSPrompt.MessageBox.MessageText.Caption



LogMessage = "Message Box: "+Message



Substring = Split(LogMessage,char(10))



For i = 0 to XXX



Substring(i) = Utilities.TrimLeft(Substring(i))



LogText = LogText&Substring(i)



Next



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

I split the string LogMessage on line feed characters with the Split command. This creates a dynamic array of Substring. Then I would like to trim the line feed characters from each element of the array. In order to loop through all the elements of the array I need to count them first.



How do I count the elements of this type of array/object?


  • hlalumiere's avatar
    hlalumiere
    Regular Contributor
    You don't really need to count them in this case, this is the reason the For...Each construct was created. Just replace your "For i = 0  To XXX" to "For Each strElement In Substring".



    If you did need to count the elements you would use the UBound function: "For i = 0 To UBound(Substring)"