BlueScreen Posted March 19, 2006 Share Posted March 19, 2006 All, Assuming I want to declare the array inside a function, and poll the array outside of it, how to do? MyFunc() msgbox (0,"",$x[0][0]) Func MyFunc () $size=5 Dim $x[$size][$size] $x[0][0]="abc" EndFunc This code is not working Link to comment Share on other sites More sharing options...
Valuater Posted March 19, 2006 Share Posted March 19, 2006 maybe Dim $x[10][10] MyFunc() msgbox (0,"",$x[0][0]) Func MyFunc () $size=5 ReDim $x[$size][$size] $x[0][0]="abc" EndFunc 8) Link to comment Share on other sites More sharing options...
GaryFrost Posted March 19, 2006 Share Posted March 19, 2006 try declaring it global and rediming it i.e. Global $x[1][1] MyFunc() msgbox (0,"",$x[0][0]) Func MyFunc () $size=5 ReDim $x[$size][$size] $x[0][0]="abc" EndFunc SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 19, 2006 Moderators Share Posted March 19, 2006 (edited) All, Assuming I want to declare the array inside a function, and poll the array outside of it, how to do? MyFunc() msgbox (0,"",$x[0][0]) Func MyFunc () $size=5 Dim $x[$size][$size] $x[0][0]="abc" EndFunc This code is not workingDo you mean something like this:MsgBox(0, '', MyFunc()) Func MyFunc () $size=5 Dim $x[$size][$size] $x[1][0] = "abc" Return $x[1][0] EndFunc?? Edit: Gary that's what I thought to begin with, but it looked like he was only trying to get the value... I am sure you are right. Edited March 19, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
BlueScreen Posted March 19, 2006 Author Share Posted March 19, 2006 Thanks, guys, Since my array's size is dynamic, I'll declare it outside of a function and use the ReDim... Just though that declaring it inside a function will declare the array in a global scope... Link to comment Share on other sites More sharing options...
GaryFrost Posted March 19, 2006 Share Posted March 19, 2006 Thanks, guys, Since my array's size is dynamic, I'll declare it outside of a function and use the ReDim... Just though that declaring it inside a function will declare the array in a global scope... Actually you can, I just like having my globals at the top MyFunc() msgbox (0,"",$x[0][0]) Func MyFunc () $size=5 Global $x[$size][$size] $x[0][0]="abc" EndFunc SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
greenmachine Posted March 19, 2006 Share Posted March 19, 2006 This would be a good time for a snip from the helpfile:The difference between Dim, Local and Global is the scope in which they are created:Dim = Local scope if the variable name doesn't already exist globally (in which case it reuses the global variable!)Global = Forces creation of the variable in the Global scopeLocal = Forces creation of the variable in the Local/Function scopeWhen using variables, the local scope is checked first and then the global scope second.So dim-ing an array in the function (when it hasn't been used) is the same as making it local, which is why you can't use it outside that function. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now