?
Solved

Array within a Function

Posted on 2014-01-29
5
Medium Priority
?
396 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 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 70

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 56

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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

752 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