dylee
dylee

Reputation: 75

Visual Basic: determine size of array after spliting

I have the following code

Sub Test()

Dim path As String
Dim pathSize As Integer

path = "1,45,6,131,13,71,35,141"
pathSize = Split(path, ",").Length

MsgBox (CStr(pathSize))

End Sub

I intended to determine the size of the path by splitting it with delimiter "," to an array containing 1, 45, 6, 131, 13, 71, 35, and 141 and measuring the size of the array. However, when I run this code, I get an error at line

pathSize = Split(path, ",").Length

with error "Object required". What am I doing wrong here?

Upvotes: 0

Views: 895

Answers (1)

Scott Craner
Scott Craner

Reputation: 152495

Try this

pathSize = Ubound(Split(path, ","))+1

Upvotes: 1

Related Questions