3

I am a beginner in Classic ASP. Need to split a string that is formed of many emails delimited by comma and the result to insert (email by email) in a table using additional code I will produce later on. Each record should have a single email address. Problem is I am stuck in an array range error. The message is:

Microsoft VBScript runtime error '800a0009'

Subscript out of range: 'WrdArray'

/NameOfFile.asp, line 3

Any hint will be highly appreciated.

Dim WrdArray()  
Dim txtToSplit 
WrdArray() = Split(txtToSplit,",")  
For i = LBound(WrdArray) To UBound(WrdArray)  
  strg = WrdArray(i)
  'CODE TO INSERT THE VALUE OF strg IN A RECORD OF THE TABLE
Next

1 Answer 1

3

You don't need a dynamic array here, just remove the () to declare a standard variable that will become a variant array when Split() is called.

Dim WrdArray
Dim txtToSplit 
WrdArray = Split(txtToSplit,",")  
For i = LBound(WrdArray) To UBound(WrdArray)  
  strg = WrdArray(i)
  'CODE TO INSERT THE VALUE OF strg IN A RECORD OF THE TABLE
Next

Dynamic array declarations are used when you need to increase the size of the array at runtime using the ReDim command. In this case Split() will always return a fixed number of results so there is no need to use a dynamic array unless you plan on adding more items later.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.