Solved Questions about Arrays

Privateer

Registered User.
Local time
Today, 12:54
Joined
Aug 16, 2011
Messages
193
I need some help with arrays. I am passing strings of different lengths, and the code is blowing up when the last element is empty. In other words, an array expecting seven elements is only getting six, or five. And to be clear, it all works fine when there are seven.

I have a string that is composed of values separated by a semi-colon. The number of values can vary, not by much, but 5 or 6 or 7. I am passing this string to a function that is splitting the values into a one-dimensional array of 7 as string. I have tried using Nz() around the last element, didn't work. The UBound() always says 6, which means seven and that didn't help because I am building that array with (0 to 6) dimensions.

What I would like is a way to build the array that is dynamic enough to handle a varying number of elements. I have seen the ReDim Preserve code, I just can't figure out how to get the upper number. I even considered counting how many semi-colons are in the source string and realized how nuts that sounded. Any help would be appreciated.
Thanks.
 
I don't use arrays much, but this is dynamic:

Dim astrLines() As String

astrLines = Split(strBody, vbCrLf)
For L = 0 To UBound(astrLines)
 
Gassman, thanks, that worked. In the Microsoft Learn world, they did not show the split code, so I had the UBound above that line of code. Then I was trying to populate the unrequired "dimension" variable. The simple phrase, and then, got me the answer. Feel like I had my head up my ass. Now I can loop through this from zero to UBound and assign the values. Thanks again.
 
If you want a dynamic array (and lots of other things) the code here makes it easy. I have this module stored so that when I am doing a lot of array stuff, I import into my db.

 

Users who are viewing this thread

Back
Top Bottom