Jump to content
Sign in to follow this  
AndreasNWWWWW

Array and functions

Recommended Posts

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

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

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
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

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

 

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By MiKa666
      Hi all,
      I'm developing a tool for exploratively testing another software. For that I wanna cover all the GUI functionality from that software and verify everything works as intended. But now I've a problem which I couldnt solve so far.
      One thing that software I'm testing does, is to load up either a single picture or a series of pictures. Depending on how much pictures got loaded, further actions will be proceeded...
      This loaded pictures are schon within a ToolbarWindow and they're clickable. What I need to know is, how much pictures are in this ToolbarWindow...
      Can anybody provide me a tip on how to achive this?
      Would be amazing!!
      BR,
      Mic
    • By meety
      Hello!
      wingettext function can get the text content of the IE browser page, but the text content of the page cannot be obtained in the chrome browser? What should I do?
    • By roeselpi
      hello again,
      it has been a long time since i have been here and a long time since i last used autoit. ever so often when the time allows me to, then i follow up on an idea that i had a long time ago. i have done all the work on paper but now it is up to writing it in autoit and i keep stumbling over many little issues here and there. sometimes after a few days i will try again and get a step further but sometimes it just will not help no matter how long i try and think about a solution. for most of you it will be the basics but for me it is not all that easy, but at least i give it a try.
      right, down to business:
      here is my code:
      #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Array.au3> #include <String.au3> ; ; PART 1: define replacements and check with msgbox ; Global $y, $z $y = "Yes" $z = "No" MsgBox(0,"replacements", $y & @CRLF & $z) ;the replacements in a message box ; ; PART 2: set the texts and check via console and msgbox ; Global $my1string = "abab" ;the first specified text MsgBox(0,"my1string", $my1string) ;the message box to output the first specified text Global $my2string = "icic" ;the second specified text MsgBox(0,"my2string", $my2string) ;the message box to output the second specified text ; ; PART 3: transform the strings to individual arrays ; $my1array = StringSplit($my1string, "") $my1array[0] = "" _ArrayDelete($my1array, 0) _ArrayDisplay($my1array, "my1array") ;the display of the first specified array $my2array = StringSplit($my2string, "") $my2array[0] = "" _ArrayDelete($my2array, 0) _ArrayDisplay($my2array, "my2array") ;the display of the first specified array ; ; PART 4: create an empty array for filling ; Global $OutputArray[4] $OutputArray[0] = "" _ArrayDisplay($OutputArray, "OutputArray") ;the display of the first specified array ; ; PART 5: compare & fill empty OutputArray with data after evaluation ; Global $i, $j, $k For $i = 0 to UBound($my1array) -1 For $j = 0 to UBound($my2array) -1 For $k = 0 to UBound($OutputArray) -1 If $my1array[$i] = "a" And $my2array[$j] = "i" Then $OutputArray[$k] = $y Else $OutputArray[$k] = $z EndIf Next Next Next _ArrayDisplay($OutputArray, "OutputArray") ;the display of the Newly filled Array In "Part 2" i make a string that is converted to an array in "Part 3" ... Now, I know that "a" and "i" are always in the exact same spot in both arrays and so i wanted to compare this and make a further array to document my findings by saying "yes" or "no" ... however my new array keeps saying just "no" allthough i can clearly see and know that it should say:
      yes no yes no my guess is that there is something wrong within my for-loops and that the counting is somehow "off" i guess that when the first for-loop is finished it reaches the second whilst the second for-loop is checking the first which would explain why it always says "no" instead of seeing the obvious.
      so my question would be: what is wrong with my for-loop? or where am i making an error that ultimately gives me the wrong results?
      help is much appreciated.
      kind regards
      roeselpi
       
       
      PS: sorry for my not so great english spelling ... stupid german sitting here trying out intermediate english skills.
    • By DirtyJohny
      Hi everyone.Need rewrite this function how in еxample.
      Original:
      #RequireAdmin #NoTrayIcon Opt("MustDeclareVars",1) Func _a() Local $sls=ObjGet("winmgmts:{impersonationLevel=impersonate," _ &"authenticationLevel=Pkt}!\\"& _ @ComputerName&'\root\wmi'),$lss=$sls.ExecQuery _ ('SELECT * FROM WmiMonitorID'), _ $lll,$sll,$sss="",$lsl,$lls,$i,$z For $z In $lss $lsl=$z.UserFriendlyName For $i=0 To Ubound($lsl)-1 if ($lsl[$i]) Then $lll&=Chr($lsl[$i]) Next $lls=$z.SerialNumberID For $i=0 To Ubound($lls)-1 if ($lls[$i]) Then $sll&=Chr($lls[$i]) Next $sss&="Model"&@TAB&@TAB&": "&$lll&@CR&"Serial Number"&@TAB&": "&$sll&@CR&@CR $lll="" $sll="" Next MsgBox(262144,'Monitors '&$lss.Count,$sss&" "&@CR) $lss=Null $sls=Null EndFunc _a() Example:
      Func _InfoPC() Local $ObjService = ObjGet('winmgmts:{impersonationLevel = impersonate}!\\' & @ComputerName & '\root\cimv2') Local $ObjMB = $ObjService.ExecQuery('SELECT * FROM Win32_BaseBoard', 'WQL', 0x30) If IsObj($ObjService) Then For $objItemMB In $ObjMB $sInfo &= @TAB & 'Motherboard: ...... ' & $objItemMB.Product & @CRLF I'm beginner in this sphere and need  you all speak easy and simply because i'm Russian.Thanks)
    • By Deshanur
      Am trying to automate injecting credential on the login form for all kind of Web application for IE. I know how to identify the form name by viewing the source code and using the method - _IEFormGetObjByName($ie, $form_Name).
      I would like to know how to identify or get the form object for the web app where there is no form name tag for example below, for the is I have used - _IEFormGetCollection($ie, 0) to get the form object.
      My Question is does it work for all kind of application "_IEFormGetCollection($ie, 0)" how to identify Index value? is it always 0? is there any better solution?
      The final solution am looking for is find out form object, get the username, password field and inject credential and submit the form.
      How to find out index value? for the forms which does not have form name field.
      $login_form = _IEFormGetCollection($ie, 0) $email_field = _IEFormElementGetObjByName($login_form, $form_UserName) $pass_field = _IEFormElementGetObjByName($login_form, $form_password) $login_button = _IEFormElementGetObjByName($login_form, $form_submitbutton) _IEFormElementSetValue($email_field, $CmdLine[2]) _IEFormElementSetValue($pass_field, $CmdLine[3]) ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]","{Enter}") OR This works fine if the form has form name. $login_form = _IEFormGetObjByName($ie, $form_Name) $email_field = _IEFormElementGetObjByName($login_form, $form_UserName) $pass_field = _IEFormElementGetObjByName($login_form, $form_password) $login_button = _IEFormElementGetObjByName($login_form, $form_submitbutton) _IEFormElementSetValue($email_field, $CmdLine[2]) _IEFormElementSetValue($pass_field, $CmdLine[3]) ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]","{Enter}")
×
×
  • Create New...