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
user692942
  • 16,398
  • 7
  • 76
  • 175
Gab2021
  • 69
  • 1
  • 11

1 Answers1

4

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.

user692942
  • 16,398
  • 7
  • 76
  • 175