- Code: Select all
test = "This,is,a,comma,delimited,string"
myArray = Split(test,",")
msgbox UBound(myArray) 'This returns 5 instead of the expected 6
You would think that the array would contain 6 elements, but for some reason is doesn't get the last element.
The fix is to attach a comma to the end of the string. You can do this without adding the comma to the variable, test, by concatenating the comma as a literal in the Split command like this:
- Code: Select all
myArray = Split(test & ",", ",")
msgbox UBound(myArray) 'Now all 6 elements are added to the array
Here is a test I ran to prove it:
- Code: Select all
sTest = "1,2,3,4,5,6"
myArray = Split(sTest,",")
Text(4).caption = UBound(myArray)
myArray2 = Split(sTest & ",",",")
Text(5).caption = UBound(myArray2)