Problem with ASP array

I'm trying to use the split function in ASP and it returns me an array.
I'm splitting a form field at the space.

But I'm getting this error on the IF statement and I have suspicion that it's when there is no space.
Subscript out of range: '[number: 1]'

What can I do to avoid this problem?
WordArray = Split(carMake, " ")

	if WordArray(0) = WordArray(1)  then 
	carMake = WordArray(0)
	end if

Open in new window

Who is Participating?
Big MontyConnect With a Mentor Senior Web Developer / CEO of Commented:
try this:

WordArray = Split(carMake, " ")
      if UBound( WordArray ) > 0 then
      if WordArray(0) = WordArray(1)  then
      carMake = WordArray(0)
      end if
      end if
check the length of the array before doing the if statement to make sure that the array is actually going to have something at WordArray(1)
rivkamakAuthor Commented:
how do you do that?
ok you can try checking the Ubound(WordArray) to make sure that that is not 0.
or you can try looping through the array and setting a counter up.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.