Solved

Array within a Function

Posted on 2014-01-29
5
392 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 33

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 70

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 54

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 53

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

732 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