Allen
Allen

Reputation: 135

How can I use a variable created within a function?

I have a function with an array inside:

Function newFunction()
  Dim newArray(1,1)
  newArray(0,0) = "1"
  newArray(1,0) = "2"
  newArray(0,1) = "3"
  newArray(1,1) = "4"
  newFunction = newArray
End Function

I want to be able to call this function on another page and write the results like this:

<%= newFunction(1,0) %>

and this should write out: 2

I keep getting the error "Wrong number of arguments or invalid property assignment" when I do this. How can this be done?

Upvotes: 0

Views: 67

Answers (4)

Nilpo
Nilpo

Reputation: 4816

Is there a reason why you want to do this in this manner? Why not just access the array itself on the second page?

Upvotes: 0

Localghost
Localghost

Reputation: 712

This is an issue with scope. Your "other page" cannot see, or doesn't have access to the definition of this function.

In order to do something like this, you need to include the file that has the definition of this function.

See: http://www.w3schools.com/asp/asp_incfiles.asp

Upvotes: 0

Kyle Sletten
Kyle Sletten

Reputation: 5413

Looks like you should actually be doing:

<%= newFunction()(1,0) %>

But I'm no expert in VB.

Upvotes: 3

Ry-
Ry-

Reputation: 224867

You need this instead:

<%= newFunction()(1, 0) %>

It thinks you're calling newFunction with arguments 1 and 0, not accessing its return value.

Upvotes: 1

Related Questions