• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

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

0
rivkamak
Asked:
rivkamak
  • 2
1 Solution
 
haloexpertsexchangeCommented:
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)
0
 
rivkamakAuthor Commented:
how do you do that?
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
try this:

WordArray = Split(carMake, " ")
      if UBound( WordArray ) > 0 then
      if WordArray(0) = WordArray(1)  then
      carMake = WordArray(0)
      end if
      end if
0
 
haloexpertsexchangeCommented:
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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now