Passing Arrays to Functions - Subscript Out of Range Problem 
Author Message
 Passing Arrays to Functions - Subscript Out of Range Problem

Hi,

I m passing an array to a function in VBScript while doing Server side
scripting.

Codes are likewise -

dim arr()
dim len
len = 5

redim preserve arr(len)

'*** a function " function test(byref arr() as string, length as integer)"
prevails **

'** Following call is made******************

test arr(),len

on executing these codes i m getting an Error Message as below -

Microsoft VBScript runtime error '800a0009'

Subscript out of range

PLEASE GUIDE ME HOW TO GET OUT OF THIS PROBLEM

thanx n regards to all of u

Bhupendra



Sat, 29 Mar 2003 03:00:00 GMT  
 Passing Arrays to Functions - Subscript Out of Range Problem

Hi,

I m passing an array to a function in VBScript while doing Server side
scripting.

Codes are likewise -

dim arr()
dim len
len = 5

redim preserve arr(len)

'*** a function " function test(byref arr() as string, length as integer)"
prevails **

'** Following call is made******************

test arr(),len

on executing these codes i m getting an Error Message as below -

Microsoft VBScript runtime error '800a0009'

Subscript out of range

PLEASE GUIDE ME HOW TO GET OUT OF THIS PROBLEM

thanx n regards to all of u

Bhupendra




Sat, 29 Mar 2003 03:00:00 GMT  
 Passing Arrays to Functions - Subscript Out of Range Problem

Quote:

> Hi,

> I m passing an array to a function in VBScript while doing Server side
> scripting.

> Codes are likewise -

> dim arr()
> dim len
> len = 5

> redim preserve arr(len)

> '*** a function " function test(byref arr() as string, length as integer)"
> prevails **

> '** Following call is made******************

> test arr(),len

> on executing these codes i m getting an Error Message as below -

> Microsoft VBScript runtime error '800a0009'

> Subscript out of range

> PLEASE GUIDE ME HOW TO GET OUT OF THIS PROBLEM

> thanx n regards to all of u

> Bhupendra



Since it is passed by reference, simply pass the Name of the variable to
the routine.  That is, drop the parentheses ...

  test arr,len

Besides that, you don't actually need to pass the length, as the Ubound
function can be used in the function to determine the upper bound
(length) of the array.

Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/



Sat, 29 Mar 2003 03:00:00 GMT  
 Passing Arrays to Functions - Subscript Out of Range Problem

Bhupendra,

Two things:

  1.  Don't use Len as a variable. VBScript already has a function
called Len.  Use something like ArrLength.

  2.  Pass Arr to the Test function without using the parentheses:

  Test Arr, ArrLength

HTH,

Chris.
---------



Sat, 29 Mar 2003 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. subscript out of range? (floating array problem)

2. Arrays Problem SUBSCRIPT OUT OF RANGE

3. array subscript out of range

4. HELP! Subscript Out Of Range error referencing array

5. Array Subscript out of range:

6. Defining an array and getting Subscript Out of Range Error

7. Subscript out of range Error when using Arrays

8. Problems With FlexGrid And Subscript Out Of Range Error

9. Subscript out of range error problem

10. Passing control array into global function - problem

11. "subscript out of range" - Excel

12. Subscript Out Of Range Error

 

 
Powered by phpBB® Forum Software