Jump to content
Sign in to follow this  
daniel02

working with global arrays [solved]

Recommended Posts

daniel02

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

Share this post


Link to post
Share on other sites
JRowe

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.

Share this post


Link to post
Share on other sites
martin

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.