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

Thoughts:

  • 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:

 

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.  :)

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

    • nooneclose
      By nooneclose
      Good morning everyone, I thought I had already solved this issue but it turns out I did not. 
      My code finds unread emails with this specific subject line of "request" but when I change the subject to SKIPPED + "request" = ("SKIPPED request") the program still finds the email and tries to process it. I only want to process emails with the exact match subject of "request".
      Here is my code that "finds" the unread emails with the subject of "request" or so I thought. 
      Func ListUnreadEmails() ;******************************************************************************* ; Lists all unread E-mails from the folder Outlook-UDF-Test ;******************************************************************************* ; Stores all the unRead emails into an array Global $aItems = _OL_ItemFind($oOutlook, "*\Outlook-UDF-Test", $olMail, _ "[UnRead]=True", "Subject", "request", "EntryID,Subject", "", 1) ; Displays the array of unRead emails If IsArray($aItems) Then ;_ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind - Unread mails") Else MsgBox(48, "OutlookEX UDF: _OL_ItemFind Example Script", _ "Could not find an unread mail. @error = " & @error & ", @extended: " & @extended) EndIf ; Gets the number of unread emails Global $numberOfUnRead = UBound($aItems, $UBOUND_ROWS) - 1 ;MsgBox("", "Number of Unread emails", $numberOfUnRead) EndFunc It acts as if any part of the subject containing the word "request" and the email is unread that it will try to process it. (I think)
    • KhalidAnsari
      By KhalidAnsari
      Hi,
      I need to automate Java application using AutoIt, I have refer forum for the same, as per forum I am using Java Access Bridge to finding control name. But could not set value to control. Below is my sample code 
      Send("#r")
      sleep(1500)
      Send("D:\javaapplication\javaapplication\Hello.jar{Enter}")
      WinActivate("Penjumlahan")
      sleep(1500)
      ControlSetText("Penjumlahan", "", "Name:  A :", "demo")
      Java Application and Java Ferret screen

    • QaisBsharat
      By QaisBsharat
      Hello, 
      May i know how can i automation qt application?
      Using controlclick not mouse and positions
       
      Thanks
    • nooneclose
      By nooneclose
      Good afternoon, I am in need of some help. I am sure this is a stupid question requiring only one or two lines of code. However, I would greatly appreciate the help I cannot figure this out. I also tried searching for the answer on the internet but no one except me apparently seems to be having a hard time figuring this out and or is asking about it. 
      I simply want to change the "status" of an email from unread to read once I have processed it. My code is over 500 lines and I would like not to clutter this post with it. Assume I have all my includes and connections properly defined and stuff. 
      Here is the bit of code where I am trying to change the email that was used from unread to read:
      Func ChangeEmailStatus() ;******************************************************************************* ; changes the status of an email from unread to Read ;******************************************************************************* Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (Before Change)", $iRows) _OL_ItemModify($oOutlook,$aItems[$i][0], Default, "Read=True") MsgBox("", "Array Display 1", $aItems[1][0]) MsgBox("", "Array Display 2", $aItems[2][0]) Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (After Change)", $iRows) EndFunc  
    • SharpDressedMan
      By SharpDressedMan
      Hello,
      Is there any way to check for validity of a pointer to a DllStruct ?
      In the above code, a DllStruct is created from an invalid pointer. How to prevent from doing this ?
      local $tStruct = DllStructCreate("int i") DllStructSetData($tStruct, "i", 123) local $pStruct = DllStructGetPtr($tStruct) $tStruct = 0 ; destroy DllStruct ==> $pStruct becomes invalid ; how to check here for validity of $pStruct and prevent from doing the following ? $tStruct = DllStructCreate("int i", $pStruct) ; create DllStruct from invalid pointer... MsgBox(0, @ScriptName, @error) ; displays '0' : invalid pointer is not detected by DllStructCreate() MsgBox(0, @ScriptName, IsDllStruct($tStruct)) ; displays '1' : tStruct is assumed as a valid DllStruct object, which is not Thanks for help
×