Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Array within a Function

Posted on 2014-01-29
5
Medium Priority
?
397 Views
Last Modified: 2014-01-30
Using Classic ASP and VBScript

I'm calling a function that creates an array in order to determine a boolean value but doesn't return that array.  It just returns the boolean value.  

After the function is called and the boolean value is returned I'd like to loop through the array that was created inside the function, but I can't seem to do that.  

Is the array only accessible within the function itself?  Is it not possible to access that array after the function is called?  Please advise.

Thank you.
0
Comment
Question by:cdemott33
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 34

Accepted Solution

by:
Big Monty earned 668 total points
ID: 39819295
would help to see some code, but I'll take a stab at it...

where do you dim the array, inside or outside the function? I believe if you do it outside you should then be able to access it.
0
 
LVL 71

Assisted Solution

by:Qlemo
Qlemo earned 668 total points
ID: 39819349
Vars always are local to the code they are created in. If the array var is defined outside of the function, it is likely you can access the content. But more likely the array is not available at all, as defined in the function completely. And that is intentionally.
0
 
LVL 58

Assisted Solution

by:Bill Prew
Bill Prew earned 664 total points
ID: 39819691
Take a look at the "scope" section of the following.

http://msdn.microsoft.com/en-us/library/t7zd6etz(v=vs.84).aspx

~bp
0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39819823
' run the function
test=myFunction("t")
arrTest=split(test,",")
option1=arrTest(0)
option2=arrTest(1)
option3=arrTest(2)
myBoolean =arrTest(3)

myFunction(x) 
  myFunction="" 
  test = 0
  dim myArray(2)
  myArray(0)=x&"1"
  myArray(0)=  x&"2"
  myArray(0)=x&"3"

for each item in myArray
    myFunction=myFunction&item&","
    if "abc" = item then
        test=1
   end if
 next
 myFunction=myFunction&test
end function

Open in new window

0
 

Author Closing Comment

by:cdemott33
ID: 39820738
You all pointed me in the right direction.  It was the scope.  Once I moved the creation of the array outside the function it worked.  Thanks again for your help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

610 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