Solved

Array within a Function

Posted on 2014-01-29
5
387 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
5 Comments
 
LVL 32

Accepted Solution

by:
Big Monty earned 167 total points
Comment Utility
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 68

Assisted Solution

by:Qlemo
Qlemo earned 167 total points
Comment Utility
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 51

Assisted Solution

by:Bill Prew
Bill Prew earned 166 total points
Comment Utility
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 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
' 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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now