Click here to Skip to main content
14,696,499 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Code Project Peeps,
I want to get all simple variables from a function or scope. How can i do this,


The code below is just pascal code




For example "Not Woking but you will understand"


Public Function TestFunction()
    Dim varone,vartwo
    varone  = "1"
    vartwo  = "2"
End Function

Public Function dump()
    for each (var item in TestFunction())
        console.write(item.name + ":" +item.var)
End Function




Console Output should be :
varone:1
vartwo:2
Posted

1 solution

You can't look into the variables of a function scope because it is private. It is the intended idea of functions and methods, to hide implementation details. You can place the writelines in the TestFunction because there the variables are still into scope.

Good luck!
   
Comments
Member 11824455 6-Aug-15 10:15am
   
thanks. I undersand but, can I find all the varibles in the same scope where, for example Public Function TestFunction()
Dim varone,vartwo
varone = "1"
vartwo = "2"
for each (var item in this)
console.write(item.name + ":" +item.var)
End Function
E.F. Nijboer 6-Aug-15 12:03pm
   
No, that is also not possible and you already have access to the variables you declared earlier. If you want to iterate over the items you could consider using an array for example.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900