Problem with ASP array

Posted on 2011-10-25
Last Modified: 2012-05-12
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

Question by:rivkamak
    LVL 13

    Expert Comment

    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)

    Author Comment

    how do you do that?
    LVL 32

    Accepted Solution

    try this:

    WordArray = Split(carMake, " ")
          if UBound( WordArray ) > 0 then
          if WordArray(0) = WordArray(1)  then
          carMake = WordArray(0)
          end if
          end if
    LVL 13

    Expert Comment

    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.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Suggested Solutions

    Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
    I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now