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

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
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 nooneclose
      I need to dynamically resize my 2d array while looping. 
      I know this code:
      ReDim $rArray[UBound($rArray) + 1] works for the rows, however, I also need to increase the columns. How would i go about increasing both rows and columns while looping? 
    • By FUD
      hello 
      please i need help 
      i need to open link in default browser only one windows without duplicate if i try to open the same link 
       
      thanks 
    • By YogendraAtluri
      Hi, 
      I am new to AutoIT scripting and I am still learning. I am trying to communicate with a Labview application that acts like a server. it basically takes commands from the client. But for some commands, it also send back some data. 
      When i am sending commands from my script, i can see that the labview is getting them. But i am not able to get anything back. I tried different code pieces that are available online in the forum.
      This is the working piece of code which i been using to send data.
      #cs This module is used to establish tcp connection with lab view #ce #include <File.au3> Func SendCmd($cmd) TCPStartup() Local $IpAddress="192.168.10.101" Local $Port="5353" $Labview = TCPConnect($IpAddress,$Port) If @error Then ConsoleWrite('!--> TCPConnect error number ( ' & @error & ' ).' & @CRLF) TCPCloseSocket($Labview) TCPShutdown() Exit EndIf TCPSend($Labview, $cmd & @CRLF) TCPCloseSocket($Labview) TCPShutdown() EndFunc SendCmd("wt42d")  
      This is slightly modified code to send and receive data, which is not working. I am not getting any response back
      SendCmd("galil") Func SendCmd($cmd) TCPStartup() Local $IpAddress="192.168.10.101" Local $Port="5353" $Labview = TCPConnect($IpAddress,$Port) If @error Then ConsoleWrite('!--> TCPConnect error number ( ' & @error & ' ).' & @CRLF) TCPCloseSocket($Labview) TCPShutdown() Exit EndIf TCPSend($Labview, $cmd & @CRLF) $ip = @IPAddress1 ;create listening socket $Listensocket = TCPListen($ip, $Port) ConsoleWrite("Listening to Socket - " & $Listensocket & @CRLF) If $Listensocket = -1 Then ConsoleWrite("Exiting..." & @CRLF) Exit EndIf ;Accept incoming clients and recieve info While 1 $connectedsocket = TCPAccept($Listensocket) ConsoleWrite("Connecting to Socket - " & $connectedsocket & "Error -" & @error & @CRLF) If $ConnectedSocket >= 0 Then $ip2 = TCPRecv($connectedsocket,1000000) EndIf WEnd TCPCloseSocket($connectedsocket) TCPCloseSocket($Labview) TCPShutdown() EndFunc I am not getting anything back. I am getting the following output in the console
      +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop. Listening to Socket - 544 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 its going through that loop forever. i need to force stop it.
      But when i open putty and send the same command, i am getting response right away. 
      Can someone please help me with that.
      Thanks in advance
      Regards
      Yogendra
    • By Bhooshan
      I need to mute an ongoing call on Microsoft teams without activating the window. Teams allows us to mute using shortcut key Ctrl+Shift+m but only when the window is active.
      # Used set option as ongoing call can be with any person which leads to change in Title Name.
      AutoItSetOption ( "WinTitleMatchMode", 2 ) 
      # I am not clear with the control ID which will be good to use here and also the key combination of ^M       
      ControlSend ( "Microsoft Teams", "", "[CLASS:Intermediate D3D Window; INSTANCE:1]", "{ctrl down}")
       
      Can anyone help...!!! 
       

    • By Sayed
      Hi there, 
      I'm new in AutoIt forms and using AutoIt to automate desktop application (able to automate the application normally but facing issue when I've to re-run the application twice within the same script...so need help in this please)
      here is the steps then followed by the issue in a brief : 
      1- run application . 
      2- do some actions (click menus,activate windows,set texts..)
      3- close the application. 
      4- run the application again & access the same controls.
      5- open the same windows again (like step 2)
      6- perform some validations (by getting texts from some text boxes)
      7- close the application again (and repeat 1-7 for 15 times in average )
      The issue 
      * all controls are accessible in the first run and actions done successfully on controls (for steps 1-3) BUT from the second run of the application from step-4 it's able to set focus only the main application window.
      Note: only unique properties used to while mapping the controls. 
      Error that appear in the console :
      UIAWrappers.au3" (1673) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $x = Int($t[1] + ($t[3] / 2)) $x = Int($t[1] + (^ ERROR  
      Simple spy code  of one of the controls that has this strange issue(menubar&view menu Item): 
      ;~ *** Standard code maintainable *** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) _UIA_setVar("oP1","Title:=XXX;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app") ;main app form xxx _UIA_setVar("oP2","Title:=menuStrip1;controltype:=UIA_MenuBarControlTypeId;class:=WindowsForms10.Window.8.app") ;menuStrip1 ;~ $oUIElement=_UIA_getObjectByFindAll("View.mainwindow", "title:=View;ControlType:=UIA_MenuItemControlTypeId", $treescope_subtree) _UIA_setVar("oUIElement","Title:=View;controltype:=UIA_MenuItemControlTypeId;class:=") ;ControlType:=UIA_MenuItemControlTypeId;classname:=") ;~ Actions split away from logical/technical definition above can come from configfiles ;~_UIA_Action("oP1","highlight") _UIA_Action("oP1","setfocus") ;~_UIA_Action("oP2","highlight") _UIA_Action("oP2","setfocus") _UIA_action("oUIElement","highlight") ;~_UIA_action("oUIElement","click")  
       
×
×
  • Create New...