Jump to content

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

 

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:

 

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

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

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By DJ143
      I have a autoit exe file which is used in upload/browse file functionality.  This has been integrated with selenium framework and I am invoking the autoit exe using Java process and runtime. 
      Now the issue is when I run the scripts and invoke the autoit exe in local it works perfectly.  But when I use selenium grid or jenkins to run the scripts in another windows server it is not working.
      Can anyone please suggest any solution for this?
    • By Hermes
      Hello, the script below will read column A from an excel file - and if a value matches in the browser, it will click the corresponding link and click on a specific button to paste the data, then writes "Completed" in Column B. It will continue to read from the excel file and do the same thing for all the remaining rows.
      #Include "Chrome.au3" #Include "wd_core.au3" #Include "wd_helper.au3" #Include "WinHttp.au3" #include <MsgBoxConstants.au3> #include <File.au3> #include <IE.au3> #include <Array.au3> #include <INet.au3> #include <AutoItConstants.au3> #include <WinAPIFiles.au3> #include <GDIPlus.au3> #include <Excel.au3> #Include "WinHttp.au3" #Include "_HtmlTable2Array.au3" Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_LoadWait($sSession) _WD_Navigate($sSession, "table1.html") _WD_LoadWait($sSession) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='main']") Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='main']") ;ConsoleWrite ("mat-table " & $sElement & @CRLF) Local $aArray1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//td[contains(@class,'data')]", $sElement, True) sleep(1000) For $i = 0 to UBound($aArray1) - 1 $aArray1[$i] = _WD_ElementAction($sSession, $aArray1[$i], 'text') Next ;_ArrayDisplay($aArray1) ;Email variables $SmtpServer = "" ; address for the smtp-server to use - REQUIRED $FromName = "Hermes" ; name from who the email was sent $FromAddress = "sender@gmail.com" ; address from where the mail should come $ToAddress = "recipient@gmail.com" ; destination address of the email - REQUIRED, use commas (,) to add more email addresses $Subject = "File not found" ; subject from the email - can be anything you want it to be $Body = "File not found!" ; the messagebody from the mail - can be left blank but then you get a blank mail $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed $CcAddress = "" ; address for cc - leave blank if not needed $BccAddress = "" ; address for bcc - leave blank if not needed $Importance = "High" ; Send message priority: "High", "Normal", "Low" $Username = "" ; username for the account used from where the mail gets sent - REQUIRED $Password = "" ; password for the account used from where the mail gets sent - REQUIRED $IPPort = 25 ; port used for sending the mail $ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS $tls = 0 ; enables/disables TLS when required Local $oAppl = _Excel_Open() Local $sWorkbook = "c:\test.xlsx" Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook) ;open excel and pass both parameters If FileExists($sWorkbook) Then ;Check if the file exist. Local $oAppl = _Excel_Open() Local $sWorkbook = "c:\test.xlsx" Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook) ;open excel and pass both parameters Local $aArray2 = _Excel_RangeRead($oWorkbook,Default,$oWorkbook.ActiveSheet.Usedrange.Columns("A:A")) Local $iIdx Local $Skipline = 0 ;0==> first line Do Local $temprf For $i = 0 To UBound($aArray2) - 1 $temprf &= $aArray2[$i] _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, ".//a[contains(@class,'edit') and contains(text(),'Edit')]") Local $aElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//a[contains(@class,'edit') and contains(text(),'Edit')]", $sElement, True) $iIdx = _ArraySearch($aArray1, $aArray2[$i]) If @error Then ContinueLoop _WD_ElementAction($sSession, $aElement[$iIdx], 'click') If $i < $Skipline Then ContinueLoop $oRange = $oWorkbook.ActiveSheet.Range("B" & $i + 1 & ":XFD" & $i + 1) _Excel_RangeCopyPaste($oWorkbook.Activesheet, $oRange) ;Paste Local $oTest4 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "pastebutton") _WD_ElementAction($sSession, $oTest4, 'click') Sleep(1000) ;Save Button Local $save3 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "button.button") _WD_ElementAction($sSession, $save3, 'click') _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "Completed", "B" & $i+1) sleep(1000) Next Until (Not @error) _Excel_Close($oWorkbook) Else _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl, $tls) Exit EndIf _WD_LoadWait($sSession) ;Attaching files to emails Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0, $tls = 0) Local $objEmail = ObjCreate("CDO.Message") $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress Local $i_Error = 0 Local $i_Error_desciption = "" If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress $objEmail.Subject = $s_Subject If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then $objEmail.HTMLBody = $as_Body Else $objEmail.Textbody = $as_Body & @CRLF EndIf $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer If Number($IPPort) = 0 then $IPPort = 25 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort ;Authenticated SMTP If $s_Username <> "" Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password EndIf ; Set security params If $ssl Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True If $tls Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendtls") = True ;Update settings $objEmail.Configuration.Fields.Update ; Set Email Importance Switch $s_Importance Case "High" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High" Case "Normal" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal" Case "Low" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low" EndSwitch $objEmail.Fields.Update ; Sent the Message $objEmail.Send $objEmail="" EndFunc ;==>_INetSmtpMailCom Local $aDir = _FileListToArrayRec(@TempDir, "scoped_dir*;chrome_*", $FLTAR_FOLDERS, $FLTAR_NORECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) Sleep(2000) For $i = 1 To $aDir[0] DirRemove($aDir[$i], $DIR_REMOVE) Next _WD_LoadWait($sSession) _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome If the excel file doesn't exists in the folder, it will send an email to a specific recipient.
      What i am trying figure out now is if the excel crashes while the script/loop is running, I want to relaunch the excel file continue to the last row before the excel crashed. So if the value of column B is not marked as "completed", it should continue from that row
      Appreciate any help that I can get to achieve this.
      table1.html test.xlsx
    • By vinnyMS
      #Include <Array.au3> #include <Constants.au3> $s = FileRead("2.txt") Local $w = StringRegExp($s, '(?is)(\b\w+\b)(?!.*\b\1\b)', 3) _ArrayColInsert($w, 1) For $i = 0 to UBound($w)-1 StringRegExpReplace($s, '(?i)\b' & $w[$i][0] & '\b', $w[$i][0]) $w[$i][1] = @extended Next _ArraySort($w, 1, 0, 0, 1) _ArrayDisplay($w) i have this script that returns 3 columns  
       
      i need to copy the  Col 0 and Col 1 as text to paste on notepad or excel
      you will have to create a "copy" button if possible
      array.au3 2.txt
    • By adityaparakh
      Hello ,
      I am trying to use Websockets in AutoIt.
      It is to fetch live stock market prices , API is provided and documentation available for python language.
      The link for the code snippet is :
      https://symphonyfintech.com/xts-market-data-front-end-api-v2/#tag/Introduction
      https://symphonyfintech.com/xts-market-data-front-end-api-v2/#tag/Instruments/paths/~1instruments~1subscription/post
       
      https://github.com/symphonyfintech/xts-pythonclient-api-sdk
       
      Second Link is to subscribe to a list of ExchangeInstruments.
      Now I would like to get live stock ltp (LastTradedPrice) for a few stocks whose "ExchangeInstrumentID" I know.
      I am able to use the WinHttp object to perform actions using simple codes like below :
      I have the secretKey and appkey and can generate the needed token. And get the unique ExchangeInstrumentID.

      Below code is just for example of how I am using WinHttp. Unrelated to socket part.
      Global $InteractiveAPItoken = IniRead(@ScriptDir & "\Config.ini", "token", "InteractiveAPItoken", "NA") $baseurl = "https://brokerlink.com/interactive/" $functionurl = "orders" $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $baseurl & $functionurl, False) $oHTTP.SetRequestHeader("Content-Type", "application/json;charset=UTF-8") $oHTTP.SetRequestHeader("authorization", $InteractiveAPItoken) $pD = '{ "exchangeSegment": "NSEFO", "exchangeInstrumentID": ' & $exchangeInstrumentID & ', "productType": "' & $producttype & '", "orderType": "MARKET", "orderSide": "' & $orderside & '", "timeInForce": "DAY", "disclosedQuantity": 0, "orderQuantity": ' & $qty & ', "limitPrice": 0, "stopPrice": 0, "orderUniqueIdentifier": "' & $orderidentifier & '"}' $oHTTP.Send($pD) $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status
          
          
      But am struggling to understand and use socket.
      Would be of great help if you can have a look at the link mentioned above and help with the code sample for AutoIt.
      To connect and listen to a socket.
      Thanks a lot
       
    • By Hermes
      Hi, I have a site that has the following elements below: 
      <div>More element here</div> <div>More element here</div> <div>More element here</div> When I do this in Auto It:
      Local $oSelectDiv = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "div") _WD_HighlightElement($sSession, $oSelectDiv, 1) I also tried to add [3], but it doesnt seems to work:
      Local $oSelectDiv = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "div[3]") _WD_HighlightElement($sSession, $oSelectDiv, 1) It always highlight the first one, but I am trying to highlight the 3rd in the list. Is there anyway to select the 3rd div without having to add any class/id in the divs, and without using XPATH? The structure of the elements in that site were built that way.
×
×
  • Create New...