Solved

Array within a Function

Posted on 2014-01-29
5
390 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
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 69

Assisted Solution

by:Qlemo
Qlemo earned 167 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 53

Assisted Solution

by:Bill Prew
Bill Prew earned 166 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 52

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

815 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