Jump to content
AndreasNWWWWW

Array and functions

Recommended Posts

AndreasNWWWWW

I got a question:  i am trying to run different functions based upon what i select in these radio buttons.(code below)

it needs to check server 1. then run function 1 or function 2 after what i selected in the checkbox.

once that function is done it moves to the next one, until it has been trough all 5 

 

iv'e tried using while loops with different while $i equals to something but then i manualy need to go in and edit the script every time.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 437, 192, 124)
$Server2 = GUICtrlCreateLabel("Server2", 216, 95, 41, 17)
$server1 = GUICtrlCreateLabel("Server1", 216, 72, 41, 17)
$server4 = GUICtrlCreateLabel("Server4", 216, 144, 41, 17)
$server3 = GUICtrlCreateLabel("Server3", 216, 119, 41, 17)
$server5 = GUICtrlCreateLabel("Server5", 216, 170, 41, 17)
$Start = GUICtrlCreateButton("Start", 240, 248, 147, 25)
$Checkbox1 = GUICtrlCreateCheckbox("function1", 288, 72, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("function2", 392, 72, 97, 17)
$Checkbox3 = GUICtrlCreateCheckbox("function1", 288, 96, 97, 17)
$Checkbox4 = GUICtrlCreateCheckbox("function2", 392, 96, 97, 17)
$Checkbox5 = GUICtrlCreateCheckbox("function1", 288, 120, 97, 17)
$Checkbox6 = GUICtrlCreateCheckbox("function2", 392, 120, 97, 17)
$Checkbox7 = GUICtrlCreateCheckbox("function1", 288, 144, 97, 17)
$Checkbox8 = GUICtrlCreateCheckbox("function2", 392, 144, 97, 17)
$Checkbox9 = GUICtrlCreateCheckbox("function1", 288, 170, 97, 17)
$Checkbox10 = GUICtrlCreateCheckbox("function2", 392, 170, 97, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

 

Share this post


Link to post
Share on other sites
FrancescoDiMuro

Hi @AndreasNWWWWW:)
So, you have five servers, and you need to run a function ( always the same, differently parameterized I guess? ), basing on which checkbox has been checked ( the first or the second one ).
I think you can easily do this with a combination of GUICtrlRead() or GUICtrlGetState() to obtain the value of the checkboxes, and then, call the appropriate function :)

Best Regards.


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

ALWAYS GOOD TO READ:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


Link to post
Share on other sites
TheXman
18 minutes ago, AndreasNWWWWW said:

I got a question:  i am trying to run different functions based upon what i select in these radio buttons.(code below)

it needs to check server 1. then run function 1 or function 2 after what i selected in the checkbox.

once that function is done it moves to the next one, until it has been trough all 5

That's funny.  I don't see any questions.

I have a question also.  Have you spent any time reading the help file to try to figure it out on your own?  From the effort you've shown, It doesn't look like it.  Try asking to some "real" questions and maybe you'll start getting some real answers.  :)


Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
Subz

I'm bored, so wrote the following example:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $aServer[6][8] ;~ Global Array
    $aServer[0][0] = 5 ;~ Server Array Count

    ;~ Server 1 Array Info
    $aServer[1][0] = Null           ;~ Reserved for Server 1 » Label Control Handle
    $aServer[1][1] = "ServerName1"  ;~ Server 1 » Label Text Value
    $aServer[1][2] = Null           ;~ Reserved for Server 1 » Function 1 » Control Handle
    $aServer[1][3] = "Function 1"   ;~ Function 1 » Text Value
    $aServer[1][4] = $GUI_UNCHECKED ;~ Server 1 » Function 1 » Check Value
    $aServer[1][5] = Null           ;~ Reserved for Server 1 » Function 2 » Control Handle
    $aServer[1][6] = "Function 2"   ;~ Function 2 » Text Value
    $aServer[1][7] = $GUI_UNCHECKED ;~ Server 1 » Function 2 » Check Value

    ;~ Server 2 Array Info
    $aServer[2][0] = Null           ;~ Reserved for Server 2 » Label Control Handle
    $aServer[2][1] = "ServerName2"  ;~ Server 2 » Label Text Value
    $aServer[2][2] = Null           ;~ Reserved for Server 2 » Function 1 » Control Handle
    $aServer[2][3] = "Function 1"   ;~ Function 1 » Text Value
    $aServer[2][4] = $GUI_UNCHECKED ;~ Server 2 » Function 1 » Check Value
    $aServer[2][5] = Null           ;~ Reserved for Server 2 » Function 2 » Control Handle
    $aServer[2][6] = "Function 2"   ;~ Function 2 » Text Value
    $aServer[2][7] = $GUI_UNCHECKED ;~ Server 2 » Function 2 » Check Value

    ;~ Server 3 Array Info
    $aServer[3][0] = Null           ;~ Reserved for Server 3 » Label Control Handle
    $aServer[3][1] = "ServerName3"  ;~ Server 3 » Label Text Value
    $aServer[3][2] = Null           ;~ Reserved for Server 3 » Function 1 » Control Handle
    $aServer[3][3] = "Function 1"   ;~ Function 1 » Text Value
    $aServer[3][4] = $GUI_UNCHECKED ;~ Server 3 » Function 1 » Check Value - Not 
    $aServer[3][5] = Null           ;~ Reserved for Server 3 » Function 2 » Control Handle
    $aServer[3][6] = "Function 2"   ;~ Function 2 » Text Value
    $aServer[3][7] = $GUI_UNCHECKED ;~ Server 3 » Function 2 » Check Value

    ;~ Server 4 Array Info
    $aServer[4][0] = Null           ;~ Reserved for Server 4 » Label Control Handle
    $aServer[4][1] = "ServerName4"  ;~ Server 4 » Label Text Value
    $aServer[4][2] = Null           ;~ Reserved for Server 4 » Function 1 » Control Handle
    $aServer[4][3] = "Function 1"   ;~ Function 1 » Text Value
    $aServer[4][4] = $GUI_UNCHECKED ;~ Server 4 » Function 1 » Check Value
    $aServer[4][5] = Null           ;~ Reserved for Server 4 » Function 2 » Control Handle
    $aServer[4][6] = "Function 2"   ;~ Function 2 » Text Value
    $aServer[4][7] = $GUI_UNCHECKED ;~ Server 4 » Function 2 » Check Value

    ;~ Server 5 Array Info
    $aServer[5][0] = Null           ;~ Reserved for Server 5 » Label Control Handle
    $aServer[5][1] = "ServerName5"  ;~ Server 5 » Label Text Value
    $aServer[5][2] = Null           ;~ Reserved for Server 5 » Function 1 » Control Handle
    $aServer[5][3] = "Function 1"   ;~ Function 1 » Text Value
    $aServer[5][4] = $GUI_UNCHECKED ;~ Server 5 » Function 1 » Check Value
    $aServer[5][5] = Null           ;~ Reserved for Server 5 » Function 2 » Control Handle
    $aServer[5][6] = "Function 2"   ;~ Function 2 » Text Value
    $aServer[5][7] = $GUI_UNCHECKED ;~ Server 5 » Function 2 » Check Value

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 437, 192, 124)
;~ Server 1 Controls
$aServer[1][0] = GUICtrlCreateLabel($aServer[1][1], 150, 72, 100, 17)
$aServer[1][2] = GUICtrlCreateCheckbox($aServer[1][3], 288, 72, 97, 17)
    GUICtrlSetState(-1, $aServer[1][4])
$aServer[1][5] = GUICtrlCreateCheckbox($aServer[1][6], 392, 72, 97, 17)
    GUICtrlSetState(-1, $aServer[1][7])

;~ Server 2 Controls
$aServer[2][0] = GUICtrlCreateLabel($aServer[2][1], 150, 95, 100, 17)
$aServer[2][2] = GUICtrlCreateCheckbox($aServer[2][3], 288, 96, 97, 17)
    GUICtrlSetState(-1, $aServer[2][4])
$aServer[2][5] = GUICtrlCreateCheckbox($aServer[2][6], 392, 96, 97, 17)
    GUICtrlSetState(-1, $aServer[2][4])

;~ Server 3 Controls
$aServer[3][0] = GUICtrlCreateLabel($aServer[3][1], 150, 119, 100, 17)
$aServer[3][2] = GUICtrlCreateCheckbox($aServer[3][3], 288, 120, 97, 17)
    GUICtrlSetState(-1, $aServer[3][4])
$aServer[3][5] = GUICtrlCreateCheckbox($aServer[3][6], 392, 120, 97, 17)
    GUICtrlSetState(-1, $aServer[3][7])

;~ Server 4 Controls
$aServer[4][0] = GUICtrlCreateLabel($aServer[4][1], 150, 144, 100, 17)
$aServer[4][2] = GUICtrlCreateCheckbox($aServer[4][3], 288, 144, 97, 17)
    GUICtrlSetState(-1, $aServer[4][4])
$aServer[4][5] = GUICtrlCreateCheckbox($aServer[4][6], 392, 144, 97, 17)
    GUICtrlSetState(-1, $aServer[4][7])

;~ Server 5 Controls
$aServer[5][0] = GUICtrlCreateLabel($aServer[5][1], 150, 170, 100, 17)
$aServer[5][2] = GUICtrlCreateCheckbox($aServer[5][3], 288, 170, 97, 17)
    GUICtrlSetState(-1, $aServer[5][4])
$aServer[5][5] = GUICtrlCreateCheckbox($aServer[5][6], 392, 170, 97, 17)
    GUICtrlSetState(-1, $aServer[5][7])

$Start = GUICtrlCreateButton("Start", 240, 248, 147, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Start
            GUICtrlSetState($Start, $GUI_DISABLE)
            For $i = 1 To $aServer[0][0]
                ;~ Check Function 1 Checked
                If BitAND(GUICtrlRead($aServer[$i][2]), $GUI_CHECKED) = $GUI_CHECKED Then
                    $aServer[$i][4] = $GUI_CHECKED
                    Function1($aServer[$i][1])
                Else
                    $aServer[$i][4] = $GUI_UNCHECKED
                EndIf
                ;~ Check Function 2 Checked
                If BitAND(GUICtrlRead($aServer[$i][5]), $GUI_CHECKED) = $GUI_CHECKED Then
                    $aServer[$i][7] = $GUI_CHECKED
                    Function2($aServer[$i][1])
                Else
                    $aServer[$i][7] = $GUI_UNCHECKED
                EndIf
            Next
            GUICtrlSetState($Start, $GUI_ENABLE)
    EndSwitch
WEnd

Func Function1($_sServerName)
    MsgBox(4096, "Function 1", "Executing Function 1 for " & $_sServerName, 5)
EndFunc

Func Function2($_sServerName)
    MsgBox(4096, "Function 2", "Executing Function 2 for " & $_sServerName, 5)
EndFunc

 

  • Like 1

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

  • Similar Content

    • Pagi
      By Pagi
       
      <a href="index.php=4143b27b41db0a40c499202865c3e24d" class="menuitem " target="\_self"> "Menu Item 1" </a>
      Can you tell me if it´s possible to click this menu button? If yes, how? Cause I have no idea, I think i should use _IETagNameGetCollection
    • mar3011
      By mar3011
      hello, I want to set in the inputbox field random key from the keyboard to which the function will be assigned, for example F4 function start notepad ALT + A function start notepad for one function. Thank you for any help.  
    • JuanFelipe
      By JuanFelipe
      Cambiar a español Hello friends, I need help with a problem I have, I want to know if there is any way to update a GUI already running, that is I have a GUI of a certain size and with a button I would like to enlarge it:
      example: $ form1 = GUICreate ("", 200,100,0,0)   When you press the button, the gui increases its size, and actuates the new size.
    • BogdanNicolescu
      By BogdanNicolescu
      While 1 / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / WEnd OR:

       
      HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate()     Exit 0 EndFunc  
      Sorry if i should't let this here to be found by newbies like me -.-'
    • santoshM
      By santoshM
      Dear friends i am facing a problem , i have created a window in autoit some time it is moving with the mouse curser even if iam not clicking the window 
×