daniel02 Posted February 6, 2009 Share Posted February 6, 2009 (edited) Hi all, I set an array in an function and than want to use it in another one. I have a GUI where you can select an Item within a combo box and than press a button to set it. When it is set I set the array. The message box is showing the right value: Func choose() $menuinhalt = GUICtrlRead($combo1) if $menuinhalt = "Mis" Then Global $arralch[15] = ["4F7B32", "83CA4E", "A6D04E", "D4C033", "D4C033", "70B138", "609342", "659436", "49762D", "1C2517", "24331D", "496338", "ADCE97", "314727", "4B5D40"] ElseIf $menuinhalt = "Kle" Then Global $arralch[16] = ["507D61", "C90DB9", "FF09FE", "FF83FF", "FF8BFF", "F613C3", "FF1C00", "FF0051", "FF056F", "FFB6FF", "FF94FF", "FF86FF", "FF00F8", "BB54AA", "BB54AA", "748D74"] EndIf MsgBox(0, "State and text of the menuitem", "state:" & $arralch[1]) EndFunc If you than select in the GUI the "start" button another function is open but MsgBox(0, "State and text of the menuitem", "state:" & $arralch[1]) is showing nothing!! How can I fill the array/a variable in a function and pass it to another one? Thanks a lot in advance Daniel Edited February 6, 2009 by daniel02 Link to comment Share on other sites More sharing options...
JRowe Posted February 6, 2009 Share Posted February 6, 2009 Declare your global array at the start of your program, after the includes. Then, in the function, use Dim and ReDim to modify the size and contents of your array. The helpfile ReDim section is very concise and helpful for this. [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] Link to comment Share on other sites More sharing options...
daniel02 Posted February 6, 2009 Author Share Posted February 6, 2009 Thanks! Problem is solved. Link to comment Share on other sites More sharing options...
martin Posted February 6, 2009 Share Posted February 6, 2009 Hi all, I set an array in an function and than want to use it in another one. I have a GUI where you can select an Item within a combo box and than press a button to set it. When it is set I set the array. The message box is showing the right value: Func choose() $menuinhalt = GUICtrlRead($combo1) if $menuinhalt = "Mis" Then Global $arralch[15] = ["4F7B32", "83CA4E", "A6D04E", "D4C033", "D4C033", "70B138", "609342", "659436", "49762D", "1C2517", "24331D", "496338", "ADCE97", "314727", "4B5D40"] ElseIf $menuinhalt = "Kle" Then Global $arralch[16] = ["507D61", "C90DB9", "FF09FE", "FF83FF", "FF8BFF", "F613C3", "FF1C00", "FF0051", "FF056F", "FFB6FF", "FF94FF", "FF86FF", "FF00F8", "BB54AA", "BB54AA", "748D74"] EndIf MsgBox(0, "State and text of the menuitem", "state:" & $arralch[1]) EndFunc If you than select in the GUI the "start" button another function is open but MsgBox(0, "State and text of the menuitem", "state:" & $arralch[1]) is showing nothing!! How can I fill the array/a variable in a function and pass it to another one? Thanks a lot in advance Daniel As Rowe suggests, but if you don't want the array to be global you could do something like this Func Main() Local $ar $ar = choose() func2($ar, 15) EndFunc ;==>Main Func choose();returns an array $menuinhalt = GUICtrlRead($combo1) If $menuinhalt = "Mis" Then Local $arralch[15] = ["4F7B32", "83CA4E", "A6D04E", "D4C033", "D4C033", "70B138", "609342", "659436", "49762D", "1C2517", "24331D", "496338", "ADCE97", "314727", "4B5D40"] ElseIf $menuinhalt = "Kle" Then Local $arralch[16] = ["507D61", "C90DB9", "FF09FE", "FF83FF", "FF8BFF", "F613C3", "FF1C00", "FF0051", "FF056F", "FFB6FF", "FF94FF", "FF86FF", "FF00F8", "BB54AA", "BB54AA", "748D74"] EndIf MsgBox(0, "State and text of the menuitem", "state:" & $arralch[1]) Return $arralch EndFunc ;==>choose Func func2($aData, $times = 1) Local $in If IsArray($aData) Then For $in = 0 To UBound($aData) - 1 ConsoleWrite(Number($aData[$in]) * $times & @CRLF) Next EndIf EndFunc ;==>func2 Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. 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