Jump to content

Search the Community

Showing results for tags 'arrays'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

  1. poker game to study, play, or whatever you want ! an old challenge of mine that I have given up #NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=poker.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ColorConstants.au3> #include <Array.au3> Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration #Region === GUI === Local $Form1_1 = GUICreate("Poker", 769, 382, 374, 395) GUISetBkColor($COLOR_TEAL) GUISetIcon(@ScriptDir & "\spade.ico") Local $Pic1 = GUICtrlCreatePic("", 20, 60, 130, 190) GUICtrlSetState(-1, $GUI_DISABLE) Local $Pic2 = GUICtrlCreatePic("", 170, 60, 130, 190) GUICtrlSetState(-1, $GUI_DISABLE) Local $Pic3 = GUICtrlCreatePic("", 320, 60, 130, 190) GUICtrlSetState(-1, $GUI_DISABLE) Local $Pic4 = GUICtrlCreatePic("", 470, 60, 130, 190) GUICtrlSetState(-1, $GUI_DISABLE) Local $Pic5 = GUICtrlCreatePic("", 620, 60, 130, 190) GUICtrlSetState(-1, $GUI_DISABLE) Local $Hold1 = GUICtrlCreateLabel("", 20, 250, 130, 33, $SS_CENTER) GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFF00) ;Yellow Local $Hold2 = GUICtrlCreateLabel("", 170, 250, 130, 33, $SS_CENTER) GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFF00) ;Yellow Local $Hold3 = GUICtrlCreateLabel("", 320, 250, 130, 33, $SS_CENTER) GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFF00) ;Yellow Local $Hold4 = GUICtrlCreateLabel("", 470, 250, 130, 33, $SS_CENTER) GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFF00) ;Yellow Local $Hold5 = GUICtrlCreateLabel("", 620, 250, 130, 33, $SS_CENTER) GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFF00) ;Yellow Local $Label1 = GUICtrlCreateLabel("", 20, 10, 587, 41, $SS_CENTER) GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFFFF) ;White Local $Label2 = GUICtrlCreateLabel("", 620, 10, 130, 33, $SS_CENTER) GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFF00) ;Yellow Local $Button1 = GUICtrlCreateButton("START", 20, 320, 735, 35) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x000000) Local $Button2 = GUICtrlCreateButton("RED", 290, 280, 100, 35) GUICtrlSetState(-1, $GUI_HIDE) Local $Button3 = GUICtrlCreateButton("BLACK", 400, 280, 100, 35) GUICtrlSetState(-1, $GUI_HIDE) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #Region === make the card === ;clubs diamonds hearts spades Local $aColor = ["clubs", "heart", "diamond", "spade"] Local $shColor = ["C", "H", "D", "S"] Local $k, $nMsg, $Str Local $at = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "jack", "queen", "king", "ace"] Local $Oat = ["102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114"] Local $aCard[53][4] $aCard[0][0] = 52 $k = 1 For $C = 0 To UBound($aColor) - 1 For $j = 0 To UBound($at) - 1 $aCard[$k][0] = $aColor[$C] & "_" & $at[$j] ; card full name $aCard[$k][1] = $shColor[$C] ; suit $aCard[$k][2] = $at[$j] ; card $aCard[$k][3] = $Oat[$j] ; order $k += 1 Next Next ReplaceInArray($aCard, "jack", "J", 2) ReplaceInArray($aCard, "queen", "Q", 2) ReplaceInArray($aCard, "king", "K", 2) ReplaceInArray($aCard, "ace", "A", 2) $aColor = 0 $shColor = 0 $at = 0 $Oat = 0 ;_ArrayDisplay($aCard) _ArrayShuffle($aCard, 1) #EndRegion === make the card === Local $Rnt = 1, $Cnt = 1, $Score = 100, $GameMode = "Play", $WinAmount Local $HandCard[6][4] $HandCard[0][0] = 5 ;******************************************************************************* While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Pic1 If GUICtrlRead($Hold1) = "" Then GUICtrlSetData($Hold1, "Hold") Else GUICtrlSetData($Hold1, "") EndIf Case $Pic2 If GUICtrlRead($Hold2) = "" Then GUICtrlSetData($Hold2, "Hold") Else GUICtrlSetData($Hold2, "") EndIf Case $Pic3 If GUICtrlRead($Hold3) = "" Then GUICtrlSetData($Hold3, "Hold") Else GUICtrlSetData($Hold3, "") EndIf Case $Pic4 If GUICtrlRead($Hold4) = "" Then GUICtrlSetData($Hold4, "Hold") Else GUICtrlSetData($Hold4, "") EndIf Case $Pic5 If GUICtrlRead($Hold5) = "" Then GUICtrlSetData($Hold5, "Hold") Else GUICtrlSetData($Hold5, "") EndIf ;------------------- Case $Hold1 Case $Button1 ;deal Button1() Case $Button2 ;red Button2() Case $Button3 ;black Button3() EndSwitch WEnd ;******************************************************************************** ;------------------------------------------------------------------------------- Func Button1() ; deal , take Select Case $GameMode = "Play" ; then deal Deal() Case $GameMode = "Black-Red" ; then take $Score = $Score + $WinAmount GUICtrlSetState($Button2, $GUI_HIDE) GUICtrlSetState($Button3, $GUI_HIDE) GUICtrlSetFont($Label1, 24, 800, 0, "MS Sans Serif") GUICtrlSetData($Label1, "") GUICtrlSetData($Label2, $Score) GUICtrlSetFont($Label2, 24, 800, 0, "MS Sans Serif") Sleep(500) GUICtrlSetFont($Label2, 17, 800, 0, "MS Sans Serif") ;GUICtrlSetFont($Label2, 17, 800, 0, "MS Sans Serif") ;GUICtrlSetColor($Label2, 0xFFFF00) ;Yellow $GameMode = "Play" GUICtrlSetData($Button1, "DEAL") GUISetBkColor($COLOR_TEAL) EndSelect EndFunc ;==>Button1 ;------------------------------------------------------------------------------- Func Button2() ;red CardColor("Red") EndFunc ;==>Button2 ;------------------------------------------------------------------------------- Func Button3() ;black CardColor("Black") EndFunc ;==>Button3 ;------------------------------------------------------------------------------- Func ReplaceInArray(ByRef $Array, $oStr, $nStr, $Col) For $i = 0 To UBound($Array) - 1 If $Array[$i][$Col] = $oStr Then $Array[$i][$Col] = $nStr ;ConsoleWrite ($oStr & " in " & $i & " to " & $nStr & @CRLF) EndIf Next ;ToConsole($Array, $Col) EndFunc ;==>ReplaceInArray ;------------------------------------------------------------------------------- Func ToConsole($Array, $Col) ;write array to console For $i = 0 To UBound($Array) - 1 ConsoleWrite($Array[$i][$Col] & " ") Next ConsoleWrite(@CRLF) EndFunc ;==>ToConsole ;------------------------------------------------------------------------------- Func TurnCards() ;TurnCards GUICtrlSetImage($Pic1, @ScriptDir & "\card\back04.jpg") GUICtrlSetImage($Pic2, @ScriptDir & "\card\back04.jpg") GUICtrlSetImage($Pic3, @ScriptDir & "\card\back04.jpg") GUICtrlSetImage($Pic4, @ScriptDir & "\card\back04.jpg") GUICtrlSetImage($Pic5, @ScriptDir & "\card\back04.jpg") EndFunc ;==>TurnCards ;------------------------------------------------------------------------------- Func Deal() ;Deal the Cards Local $C, $R If $Rnt = 1 Then TurnCards() Sleep(300) _ArrayShuffle($aCard, 1) ckHolder() $Score = $Score - 1 GUICtrlSetData($Label2, $Score) GUICtrlSetImage($Pic1, @ScriptDir & "\card\" & $aCard[1][0] & ".jpg") GUICtrlSetImage($Pic2, @ScriptDir & "\card\" & $aCard[2][0] & ".jpg") GUICtrlSetImage($Pic3, @ScriptDir & "\card\" & $aCard[3][0] & ".jpg") GUICtrlSetImage($Pic4, @ScriptDir & "\card\" & $aCard[4][0] & ".jpg") GUICtrlSetImage($Pic5, @ScriptDir & "\card\" & $aCard[5][0] & ".jpg") For $C = 0 To 3 For $R = 1 To 5 $HandCard[$R][$C] = $aCard[$R][$C] Next Next ;_ArrayDisplay($HandCard, "Deal") ToConsole($HandCard, 2) $Rnt = 2 $Cnt = 6 Else If GUICtrlRead($Hold1) = "" Then GUICtrlSetImage($Pic1, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg") $HandCard[1][0] = $aCard[$Cnt][0] $HandCard[1][1] = $aCard[$Cnt][1] $HandCard[1][2] = $aCard[$Cnt][2] $HandCard[1][3] = $aCard[$Cnt][3] $Cnt += 1 EndIf If GUICtrlRead($Hold2) = "" Then GUICtrlSetImage($Pic2, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg") $HandCard[2][0] = $aCard[$Cnt][0] $HandCard[2][1] = $aCard[$Cnt][1] $HandCard[2][2] = $aCard[$Cnt][2] $HandCard[2][3] = $aCard[$Cnt][3] $Cnt += 1 EndIf If GUICtrlRead($Hold3) = "" Then GUICtrlSetImage($Pic3, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg") $HandCard[3][0] = $aCard[$Cnt][0] $HandCard[3][1] = $aCard[$Cnt][1] $HandCard[3][2] = $aCard[$Cnt][2] $HandCard[3][3] = $aCard[$Cnt][3] $Cnt += 1 EndIf If GUICtrlRead($Hold4) = "" Then GUICtrlSetImage($Pic4, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg") $HandCard[4][0] = $aCard[$Cnt][0] $HandCard[4][1] = $aCard[$Cnt][1] $HandCard[4][2] = $aCard[$Cnt][2] $HandCard[4][3] = $aCard[$Cnt][3] $Cnt += 1 EndIf If GUICtrlRead($Hold5) = "" Then GUICtrlSetImage($Pic5, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg") $HandCard[5][0] = $aCard[$Cnt][0] $HandCard[5][1] = $aCard[$Cnt][1] $HandCard[5][2] = $aCard[$Cnt][2] $HandCard[5][3] = $aCard[$Cnt][3] $Cnt += 1 EndIf ckHolder() ToConsole($HandCard, 2) ChekForWin() $Rnt = 1 EndIf EndFunc ;==>Deal ;------------------------------------------------------------------------------- Func ckHolder() ;Check the Holders If GUICtrlRead($Label2) = "" Then GUICtrlSetData($Label2, $Score) If $Rnt = 1 Then ConsoleWrite("********************" & @CRLF) ConsoleWrite($Rnt & " Round ------------" & @CRLF) GUICtrlSetData($Button1, "OK") GUICtrlSetFont($Label1, 18, 800, 0, "MS Sans Serif") GUICtrlSetData($Label1, "hold your cards") GUICtrlSetState($Pic1, $GUI_ENABLE) GUICtrlSetState($Pic2, $GUI_ENABLE) GUICtrlSetState($Pic3, $GUI_ENABLE) GUICtrlSetState($Pic4, $GUI_ENABLE) GUICtrlSetState($Pic5, $GUI_ENABLE) GUICtrlSetData($Hold1, "") GUICtrlSetData($Hold2, "") GUICtrlSetData($Hold3, "") GUICtrlSetData($Hold4, "") GUICtrlSetData($Hold5, "") ElseIf $Rnt = 2 Then ConsoleWrite($Rnt & " Round ------------" & @CRLF) GUICtrlSetData($Button1, "DEAL") ;GUICtrlSetFont($Label1, 12, 800, 0, "MS Sans Serif") GUICtrlSetData($Label1, "") GUICtrlSetState($Pic1, $GUI_DISABLE) GUICtrlSetState($Pic2, $GUI_DISABLE) GUICtrlSetState($Pic3, $GUI_DISABLE) GUICtrlSetState($Pic4, $GUI_DISABLE) GUICtrlSetState($Pic5, $GUI_DISABLE) GUICtrlSetData($Hold1, "") GUICtrlSetData($Hold2, "") GUICtrlSetData($Hold3, "") GUICtrlSetData($Hold4, "") GUICtrlSetData($Hold5, "") ElseIf $Rnt = 3 Then EndIf EndFunc ;==>ckHolder ;------------------------------------------------------------------------------- Func ChekForWin() ;Check for Win Local $tmpHand, $CardStr = "" _ArraySort($HandCard, 0, 1, 0, 3) ; array sort by card order ;_ArrayDisplay($HandCard, "ChekForWin") ;------------------------------------------------------------------------------------ ; Flush For $i = 1 To $HandCard[0][0] $CardStr = $CardStr & $HandCard[$i][1] Next Select Case $CardStr = "CCCCC" $tmpHand = "Flush" Case $CardStr = "DDDDD" $tmpHand = "Flush" Case $CardStr = "HHHHH" $tmpHand = "Flush" Case $CardStr = "SSSSS" $tmpHand = "Flush" EndSelect ;------------------------------------------------------------------------------------ $CardStr = "" For $i = 1 To $HandCard[0][0] $CardStr = $CardStr & $HandCard[$i][2] Next ConsoleWrite("ChekForWin ---------" & @CRLF) ConsoleWrite("$CardStr = " & $CardStr & @CRLF) ConsoleWrite("$tmpHand1 = " & $tmpHand & @CRLF) ;------------------------------------------------------------------------------------ If $tmpHand = "Flush" Then Select Case StringInStr($CardStr, "10JQKA") > 0 And $tmpHand = "Flush" $tmpHand = "Royal Flush" Case StringInStr($CardStr, "910JQK") > 0 And $tmpHand = "Flush" $tmpHand = "Straight Flush" Case StringInStr($CardStr, "8910JQ") > 0 And $tmpHand = "Flush" $tmpHand = "Straight Flush" Case StringInStr($CardStr, "78910J") > 0 And $tmpHand = "Flush" $tmpHand = "Straight Flush" Case StringInStr($CardStr, "678910") > 0 And $tmpHand = "Flush" $tmpHand = "Straight Flush" Case StringInStr($CardStr, "56789") > 0 And $tmpHand = "Flush" $tmpHand = "Straight Flush" Case StringInStr($CardStr, "45678") > 0 And $tmpHand = "Flush" $tmpHand = "Straight Flush" Case StringInStr($CardStr, "34567") > 0 And $tmpHand = "Flush" $tmpHand = "Straight Flush" Case StringInStr($CardStr, "23456") > 0 And $tmpHand = "Flush" $tmpHand = "Straight Flush" Case Else $tmpHand = "Flush" EndSelect Else Select Case StringInStr($CardStr, "2222") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "3333") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "4444") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "5555") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "6666") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "7777") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "8888") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "9999") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "10101010") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "JJJJ") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "QQQQ") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "KKKK") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "AAAA") > 0 $tmpHand = "Four of kind" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "22333") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22444") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22555") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22666") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22777") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22888") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22999") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22101010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22JJJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22QQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22KKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22AAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22233") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22244") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22255") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22266") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22277") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22288") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22299") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "2221010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "222JJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "222QQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "222KK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "222AA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "33444") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33555") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33666") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33777") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33888") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33999") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33101010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33JJJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33QQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33KKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33AAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33344") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33355") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33366") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33377") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33388") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33399") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "3331010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "333JJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "333QQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "333KK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "333AA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------" Case StringInStr($CardStr, "44555") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44666") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44777") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44888") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44999") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44101010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44JJJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44QQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44KKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44AAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44455") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44466") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44477") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44488") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44499") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "4441010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "444JJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "444QQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "444KK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "444AA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "55666") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55777") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55888") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55999") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55101010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55JJJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55QQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55KKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55AAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55566") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55577") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55588") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55599") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "5551010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "555JJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "555QQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "555KK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "555AA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "66777") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66888") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66999") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66101010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66JJJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66QQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66KKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66AAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66677") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66688") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66699") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "6661010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "666JJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "666QQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "666KK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "666AA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "77888") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "77999") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "77101010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "77JJJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "77QQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "77KKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "77AAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "77788") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "77799") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "7771010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "777JJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "777QQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "777KK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "777AA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "88999") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "88101010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "88JJJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "88QQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "88KKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "88AAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "88899") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "8881010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "888JJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "888QQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "888KK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "888AA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "99101010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "99JJJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "99QQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "99KKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "99AAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "9991010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "999JJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "999QQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "999KK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "999AA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "1010JJJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "1010QQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "1010KKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "1010AAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "101010JJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "101010QQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "101010KK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "101010AA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "JJQQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "JJKKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "JJAAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "JJJQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "JJJKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "JJJAA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "QQKKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "QQAAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "QQQKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "QQQAA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "KKAAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "KKKAA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "10JQKA") > 0 $tmpHand = "Straight" Case StringInStr($CardStr, "910JQK") > 0 $tmpHand = "Straight" Case StringInStr($CardStr, "8910JQ") > 0 $tmpHand = "Straight" Case StringInStr($CardStr, "78910J") > 0 $tmpHand = "Straight" Case StringInStr($CardStr, "678910") > 0 $tmpHand = "Straight" Case StringInStr($CardStr, "56789") > 0 $tmpHand = "Straight" Case StringInStr($CardStr, "45678") > 0 $tmpHand = "Straight" Case StringInStr($CardStr, "34567") > 0 $tmpHand = "Straight" Case StringInStr($CardStr, "23456") > 0 $tmpHand = "Straight" Case StringInStr($CardStr, "A2345") > 0 $tmpHand = "Straight" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "222") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "333") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "444") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "555") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "666") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "777") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "888") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "999") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "101010") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "JJJ") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "QQQ") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "KKK") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "AAA") > 0 $tmpHand = "Three of kind" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "33") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "44") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "55") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "66") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "77") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "88") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "99") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "1010") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "JJ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "44") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "55") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "66") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "77") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "88") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "99") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "1010") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "JJ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "55") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "66") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "77") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "88") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "99") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "1010") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "JJ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "66") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "77") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "88") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "99") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "1010") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "JJ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "77") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "88") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "99") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "1010") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "JJ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "88") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "99") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "1010") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "JJ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "88") > 0 And StringInStr($CardStr, "99") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "88") > 0 And StringInStr($CardStr, "1010") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "88") > 0 And StringInStr($CardStr, "JJ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "88") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "88") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "88") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "99") > 0 And StringInStr($CardStr, "1010") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "99") > 0 And StringInStr($CardStr, "JJ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "99") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "99") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "99") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "1010") > 0 And StringInStr($CardStr, "JJ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "1010") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "1010") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "1010") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "JJ") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "JJ") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "JJ") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "QQ") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "QQ") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "KK") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "22") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "33") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "44") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "55") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "66") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "77") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "88") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "99") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "1010") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "JJ") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "QQ") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "KK") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "AA") > 0 $tmpHand = "Pair" ;------------------------------------------------------------------------------------ EndSelect EndIf ConsoleWrite("$tmpHand2 = " & $tmpHand & @CRLF) If $tmpHand = "" Then ;nothing to win Else TakeWin($tmpHand) EndIf EndFunc ;==>ChekForWin ;------------------------------------------------------------------------------- Func TakeWin($Hand) ;amount to take Local $Msg Select ;win $Hand Case $Hand = "Royal Flush" $WinAmount = 89 Case $Hand = "Straight Flush" $WinAmount = 55 Case $Hand = "Flush" $WinAmount = 34 Case $Hand = "Four of kind" $WinAmount = 21 Case $Hand = "Full house" $WinAmount = 13 Case $Hand = "Straight" $WinAmount = 8 Case $Hand = "Three of kind" $WinAmount = 5 Case $Hand = "Two pair" $WinAmount = 3 Case $Hand = "Pair" $WinAmount = 2 EndSelect GUICtrlSetState($Button1, $GUI_DISABLE) GUICtrlSetFont($Label1, 24, 800, 0, "MS Sans Serif") GUICtrlSetData($Label1, $Hand) ; blink GUICtrlSetColor($Label1, 0xFF0000) ;red Sleep(300) GUICtrlSetColor($Label1, 0xFFFFFF) ;White Sleep(300) GUICtrlSetColor($Label1, 0xFF0000) ;red Sleep(300) GUICtrlSetColor($Label1, 0xFFFFFF) ;White Sleep(300) GUICtrlSetColor($Label1, 0xFF0000) ;red Sleep(300) GUICtrlSetColor($Label1, 0xFFFFFF) ;White ConsoleWrite("TakeWin ------------" & @CRLF) BlackRed() EndFunc ;==>TakeWin ;------------------------------------------------------------------------------- Func BlackRed() ;Black Red bet Local $Msg TurnCards() $Msg = "Win amount " & $WinAmount & ", choose black - red to double it or press take to take it" ;GUICtrlSetFont($Label1, 24, 800, 0, "MS Sans Serif") GUICtrlSetFont($Label1, 12, 800, 0, "MS Sans Serif") GUICtrlSetData($Label1, $Msg) $GameMode = "Black-Red" GUICtrlSetData($Button1, "TAKE") GUISetBkColor($COLOR_PURPLE) ; will change background color GUICtrlSetState($Button1, $GUI_ENABLE) GUICtrlSetState($Button2, $GUI_SHOW) GUICtrlSetState($Button3, $GUI_SHOW) ;GUICtrlSetState($Button1, $GUI_ENABLE) ConsoleWrite("Win amount = " & $WinAmount & @CRLF) EndFunc ;==>BlackRed ;------------------------------------------------------------------------------- Func CardColor($crdColor) ; check Black Red bet Local $Par1, $Par2 If $crdColor = "Red" Then $Par1 = "D" $Par2 = "H" Else $Par1 = "C" $Par2 = "S" EndIf Local $X = $Cnt, $CardColor $Cnt += 1 GUICtrlSetImage($Pic3, @ScriptDir & "\card\" & $aCard[$X][0] & ".jpg") Sleep(1000) $CardColor = $aCard[$X][1] If $CardColor = $Par1 Or $CardColor = $Par2 Then ;win $WinAmount = $WinAmount + $WinAmount BlackRed() Else $WinAmount = 0 ConsoleWrite("Win amount = " & 0 & @CRLF) TurnCards() GUICtrlSetState($Button2, $GUI_HIDE) GUICtrlSetState($Button3, $GUI_HIDE) GUICtrlSetFont($Label1, 24, 800, 0, "MS Sans Serif") GUICtrlSetData($Label1, "") GUICtrlSetData($Label2, $Score) $GameMode = "Play" GUICtrlSetData($Button1, "DEAL") GUISetBkColor($COLOR_TEAL) EndIf EndFunc ;==>CardColor ;------------------------------------------------------------------------------- Please, leave your comments and experiences here Thank you ! card_deck.zip RegExp shorter version 🏆 thanks to @jugador
  2. Suppose I have a 1-D array with a number of values in it such as Local $aArray[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Then I want to select one of the values that should become the new first element, with the other elements rotating into new positions while keeping the array size the same. For example, if I wanted $aArray[4] to become $aArray[0] and end up with an array that looks like this: 4 5 6 7 8 9 0 1 2 3 What would be the most efficient way to accomplish this, keeping in mind that the actual arrays I want to do this with will be much larger than this little sample one. Here's a working method I've come up with using _ArrayExtract and _ArrayConcatenate but I'm not sure if there's a better way. #include <Array.au3> Local $aArray[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] _ArrayDisplay($aArray, "BEFORE rotation") _ArrayRotate($aArray, 4) _ArrayDisplay($aArray, "AFTER rotation") Exit Func _ArrayRotate(ByRef $aArray, $iMakeFirst) ; $aArray = array to be rotated ; $iMakeFirst = element number to be rotated into position [0] ; Returns True if successful, False if not If Not IsArray($aArray) Then Return False ; invalid array If ($iMakeFirst < 0) Or ($iMakeFirst > UBound($aArray) - 1) Then Return False ; $iMakeFirst parameter is out of bounds If $iMakeFirst = 0 Then Return True ; no rotation needed, it's already the first element Local $aFirst = _ArrayExtract($aArray, $iMakeFirst) Local $aLast = _ArrayExtract($aArray, 0, $iMakeFirst - 1) Local $iResult = _ArrayConcatenate($aFirst, $aLast) If $iResult <> -1 Then $aArray = $aFirst Return True Else Return False EndIf EndFunc ;==>_ArrayRotate
  3. Please help with this 3D Array the first example works the secound doesn't. Need help to understand how Arrays work. Many thanks in advance ;First Example Dim $aArray[2][2][2] $aArray[0][0][0] = 1 $aArray[0][0][1] = 2 $aArray[0][1][0] = 3 $aArray[0][1][1] = 4 $aArray[1][0][0] = 5 $aArray[1][0][1] = 6 $aArray[1][1][0] = 7 $aArray[1][1][1] = 8 For $a = 0 to 1 for $b = 0 to 1 for $c = 0 to 1 ConsoleWrite($aArray[$a][$b][$c] & @CRLF) Next Next Next ;Secound Example Local $aArraym [2][2][2]=[[[1,2,],[3,4],[5,6],[7,8]]] For $a = 0 to 1 for $b = 0 to 1 for $c = 0 to 1 ConsoleWrite($aArraym[$a][$b][$c] & @CRLF) Next Next Next
  4. Okay I know this will be one of those - how stupid can I be when I see the answer but I'm baffled at the current time. #include <Debug.au3> Local $aArray[11][2] = [ [10,10],[1,5],[2,0],[3,0],[4,"M"],[5,0],[6,0],[7,0],[8,"M"],[9,0],[10,2] ] _DebugArrayDisplay($aArray, "$aArray") Local $iCount = 0 ;init Local $i For $i = 1 to $aArray[0][0] If $aArray[$i][1] = "M" Then $iCount = $iCount + 1 ;debug ;MsgBox($MB_OK + $MB_TOPMOST, "Debug", "$aArray[$i][0] = " & $aArray[$i][0] & @CRLF & "$aArray[$i][1] = " & $aArray[$i][1]) EndIf Next MsgBox($MB_OK + $MB_TOPMOST, "Info", "M's found = " & $iCount) When I run this it states there are 8 M's in the array.
  5. I was running my script and everything was working fine and then it just stopped working. I got this error message: !>12:51:55 AutoIt3.exe ended.rc:-1073741819 +>12:51:55 AutoIt3Wrapper Finished. >Exit code: 3221225477 Time: 354.6 I looked that error up and this article (https://www.autoitscript.com/trac/autoit/ticket/2541) said it was fixed a long time ago. I am using version: SciTE Version 4.1.0, how am I getting this error? (first time I got it after running my code 50+ times) it crashed while trying to loop through emails. Full output log: >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" /run /prod /ErrorStdOut /in "C:\" /UserParams +>12:46:01 Starting AutoIt3Wrapper v.18.708.1148.0 SciTE v.4.1.0.0 Keyboard:00000409 OS:WIN_10/ CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE >Running AU3Check (3.3.14.5) from:C:\Program Files (x86)\AutoIt3 +>12:46:01 AU3Check ended.rc:0 >Running:(3.3.14.5): --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop Action 1: Create a connection to the outlook account at line: 192 Action 1: Finished at line: 205 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Current email has been changed from Unread to Read. at line: 238 Current email has been changed from Unread to Read. at line: 238 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 3: Store vaild E-mails at line: 258 Number of unread E-mails: 17 at line: 290 Action 3: Finished at line: 292 Current number of processed Emails is: 0 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Description. Suite not needed. at line: 2180 Action 7: Finished at line: 2186 Opening a new Chrome window. at line: 2747 Action 8: Open Web Browser at line: 2240 _WDStartup: "MicrosoftWebDriver.exe" --verbose Action 8: Finished at line: 2270 Action 9: Navigate to Work Order Tracking at line: 2281 Action 9: Finished at line: 2295 Action 10: Click on Create New Work Order at line: 2306 Action 10: Finished Action 11: Send E-mail Data to it's proper field at line: 2324 Sub-Action 3: Split Long Description at line: 2522 Sub-Action 3: Finished at line: 2576 Work Order Number: 660308 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 1 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Description. Suite not needed. at line: 2180 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Work Order Number: 660309 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 2 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Description. Suite not needed. at line: 2180 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Sub-Action 3: Split Long Description at line: 2522 Sub-Action 3: Finished at line: 2576 Work Order Number: 660310 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 3 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Description. Suite not needed. at line: 2180 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Work Order Number: 660311 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 4 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Description. Suite not needed. at line: 2180 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Work Order Number: 660312 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 5 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Description. Suite not needed. at line: 2180 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Work Order Number: 660313 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 6 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Proper Building format used. Send Location: YT6508 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Long Description. Suite not needed. at line: 1475 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Work Order Number: 660314 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 7 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Proper Building format used. Send Location: CN2116 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Long Description. Suite not needed. at line: 1475 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Sub-Action 3: Split Long Description at line: 2522 Sub-Action 3: Finished at line: 2576 Work Order Number: 660315 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 8 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Proper Building format used. Send Location: DT4905 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Work Order Number: 660316 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 9 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Proper Building format used. Send Location: YT6513 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 Young Tower has no suites! Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Sub-Action 3: Split Long Description at line: 2522 Sub-Action 3: Finished at line: 2576 Work Order Number: 660317 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 10 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Proper Building format used. Send Location: BT3310 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Long Description. Suite not needed. at line: 1475 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Sub-Action 3: Split Long Description at line: 2522 Sub-Action 3: Finished at line: 2576 Work Order Number: 660318 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 11 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Proper Building format used. Send Location: BT3411 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Description. Suite not needed. at line: 2180 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Sub-Action 3: Split Long Description at line: 2522 Sub-Action 3: Finished at line: 2576 Work Order Number: 660319 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 12 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Proper Building format used. Send Location: DT4519 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Description. Suite not needed. at line: 2180 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Sub-Action 3: Split Long Description at line: 2522 Sub-Action 3: Finished at line: 2576 Work Order Number: 660320 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 13 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 !>12:51:55 AutoIt3.exe ended.rc:-1073741819 +>12:51:55 AutoIt3Wrapper Finished. >Exit code: 3221225477 Time: 354.6
  6. I am unable to execute the below script, my requirement is to copy the content from active excel sheet and to display the same. Please let me know where i am missing! #include <Excel.au3> #include <MsgBoxConstants.au3> #include <Array.au3> #include <StringConstants.au3> Local $oExcel = _Excel_Open() $LastRow2 = $oExcel.UsedRange.Rows.Count $Tissue = _Excel_RangeRead($oExcel, Default, "E1:E" & $LastRow2) $TshNr = _Excel_RangeRead($oExcel, Default, "F1:F" & $LastRow2) _ArrayDisplay($Tissue) _ArrayDisplay($TshNr)
  7. So I have been reading on how to use OAuth2 Service accounts(https://developers.google.com/identity/protocols/OAuth2ServiceAccount) and ran into an issue with autoit I can not solve. To keep this short to communicate to the Google API I need to use a JSON Web signature containing {Base64url encoded header}.{Base64url encoded claim set}. The Header and claim set work fine but I do not know how to convert them to a byte array using autoit. I have looked around on the forums and website but have not found anything that seems to work. Here is my code. #include-once #include <Array.au3> #include <Constants.au3> #include <Debug.au3> #include <File.au3> #include "Json.au3" #include <Process.au3> #include <ProgressConstants.au3> #include <String.au3> #include <WindowsConstants.au3> #include "WinHttp.au3" #include <UnixTime.au3> #include <StringConstants.au3> Global $UnixTime = _TimeGetStamp() $sJWTheader = '{"alg":"RS256","typ":"JWT"}' $sJWTclaimset = '{"iss":"Removed@forprivacy.com","scope":"https://www.googleapis.com/auth/spreadsheets","aud":"https://www.googleapis.com/oauth2/v4/token","exp":' & $UnixTime + 3600 & ',"iat":' & $UnixTime & '}' Local $taiData = DllStructCreate("BYTE[256]") Local $sText = _base64($sJWTheader)&'.'&_base64($sJWTclaimset) DllStructSetData($taiData, 1, StringToBinary($sText, 4)) Local $bvResult = DllStructGetData($taiData, 1) $sJWTSigature = $bvResult $sJWT = _base64($sJWTheader)&'.'&_base64($sJWTclaimset)&'.'&_base64($sJWTSigature) $POSTHeader = "Content-Type: application/x-www-form-urlencoded" $hOpen = _WinHttpOpen() $hConnect = _WinHttpConnect($hOpen, "https://www.googleapis.com/") $sRead = _WinHttpSimpleSSLRequest($hConnect, "POST", "oauth2/v4/token", Default, "grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=" & $sJWT) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) ConsoleWrite($sRead & @LF) The whole bytes thing is beyond with what I know about auotit. I can't tell what I need to fix.
  8. Hi, first of all thanks to all the guys who always help people in the forums, I wouldn't be able to do anything if wasn't for your help, even if I don't ask it myself. I've created this code to get some info on a monitoring network on my work. It relays on _IETableGetCollection and _IETableWriteToArray. It works well, but take around 3:25 minutes to get the info from 28 pages (some of them are large and take longer to load, but most of them are small and fast). My question is if you see a way to get the program to go faster... I've tried to make it easy for you to understand and edited somethings with sensitive info. (Some of the pages doesn't have the black divider with MIRA in the end, so I need to search if it is there or not.) #include <IE.au3> #include <array.au3> Local $oIE = _IECreate("about:blank", 0, 0) Local $paginas[28] = [89, 90, 91, 92, 93, 96, 105, 113, 119, 125, 126, 129, 131, 133, 135, 137, 139, 140, 141, 144, 145, 146, 148, 149, 150, 151, 158, 159] Local $Datos_array[0][2] Local $oTable Local $tabla Local $aux_x = 1 Local $ar = 1 Local $Numtables_datos = 0 MsgBox(0, "asd", "asd") For $pag = 0 To UBound($paginas) - 1 Step 1 _IENavigate($oIE, "<WEBSITE URL>" & $paginas[$pag]) ; <<< the pages to load are always the same except for the last digits. _ArrayAdd($Datos_array, $paginas[$pag] & "|" & "Entrante", 0, "|") ; <<<<<<<<<<<<<<<< adds the page number toarray [0, 0] ;############################################ START counts amount of tables with traffic $oTable = _IETableGetCollection($oIE) Local $iNumTables = @extended For $i = 3 To $iNumTables - 2 Step 1 $oTable = _IETableGetCollection($oIE, $i) $nomb_tabla2 = _IETableWriteToArray($oTable) ; <<<<<<<< TABLE TO ARRAY. $string2 = StringStripWS($nomb_tabla2[1][0], 8) If $string2 <> "MIRA" Then $Numtables_datos = $Numtables_datos + 1 Next $tabla_End = $iNumTables - $Numtables_datos ;############################################ FIN $tabla_Start = 4 $tabla_trafico = 2 For $for = 1 To $Numtables_datos Step 1 $oTable = _IETableGetCollection($oIE, $tabla_Start - 1) ; <<<<<<<<<<< NAME OF THE TABLE; row2 = mira $nomb_tabla = _IETableWriteToArray($oTable) ; <<<<<<<< TABLE TO ARRAY ;########################################### ADDS the traffic number into the row $string = StringStripWS($nomb_tabla[1][0], 8) If $string == "MIRA" Then ;si o si pasa por aca 1 vez _ArrayAdd($Datos_array, $nomb_tabla[0][0]) $nomb_aux = $nomb_tabla[0][0] $aux_x = 1 $tabla_trafico = $tabla_trafico + 2 Else ;esto deberia ser por row _ArrayAdd($Datos_array, $nomb_aux & " " & $aux_x) $aux_x = $aux_x + 1 $tabla_trafico = $tabla_trafico + 1 EndIf $oTable = _IETableGetCollection($oIE, $tabla_trafico) Local $aTableData = _IETableWriteToArray($oTable) $bps = _ArrayToString($aTableData, "|", 0, 0, @CRLF, 0, 0) $bps = StringRight($bps, 5) $bps = StringLeft($bps, 4) $trafico_actual = _ArrayToString($aTableData, "|", 0, 0, @CRLF, 2, 2) If $bps == "Gbps" Then $trafico_actual = $trafico_actual * 1000 If $bps == "Kbps" Then $trafico_actual = $trafico_actual / 1000 $Datos_array[$ar][1] = $trafico_actual $ar = $ar + 1 If $string == "MIRA" Then $tabla_Start = $tabla_Start + 2 Else $tabla_Start = $tabla_Start + 1 EndIf Next $ar = $ar + 1 ;~ ############# CAÍDA ############ ;~ If $actual_entrante = 0 Then ;~ $xxx = 0 ;~ Do ;~ MsgBox(0, "Tráfico Caído", $paginas[$i], 5) ;~ $xxx = $xxx + 1 ;~ Until $xxx = 10 ;~ EndIf ;~ ############# CAÍDA ############. Local $Numtables_datos = 0 Next _ArrayDisplay($Datos_array, "Array display") _IEQuit($oIE) Thanks!! monitoria.html
  9. Hello, I have recently tried experimenting with a new feature that I want to add to my program. I wanted to test packet loss, so I opted into a command prompt that displays the necessary data that I want. Now I want to sort out the data by using column sorting if possible by using arrays. My question is: Are you able to sort them out on CMD or is it only Excel spreadsheets? Below find the column I want to sort out: Pinging google.ie [2a00:1450:400b:c01::5e] with 32 bytes of data: Reply from 2a00:1450:400b:c01::5e: time=1033ms Reply from 2a00:1450:400b:c01::5e: time=309ms Reply from 2a00:1450:400b:c01::5e: time=37ms Reply from 2a00:1450:400b:c01::5e: time=732ms Ping statistics for 2a00:1450:400b:c01::5e: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 37ms, Maximum = 1033ms, Average = 527ms I want to extract the Packet loss; the average along with all the results in the "time" column. Looking forward for your response! Kind Regards, Supra
  10. The _ArraySortc() function _ArraySortC(ByRef $aArray, $iDescending = 0, $iStart = 0, $iEnd = 0, $iSubItem = 0, $iPivot = 0, $iCase = 0, $iNumericalSort = 0) The _ArraySort() function from AutoIt's Array.au3 UDF include file is downwardly compatible with the _ArraySortc() function which is in the updated ArrayMultiSortCase.au3 UDF of post #1. In fact, the _ArraySortc() function is a modified version of the _ArraySort() function that gives access to optional numeric sorting and\or case sensitive sorting if needed. The _ArraySortInOrder() function _ArraySortInOrder(ByRef $array, $sSortingOrder, $iDescending = 0, $iStartRow = 0, $iEndRow = 0, $iSubItem = 0, $iPivot = 0, $iCase = 0, $iNumericalSort = 0) The _ArraySortInOrder() function is an updated, better version from here. The update fixes a bug when zero is sorted and is made similar to (and uses) the new _ArraySortc() function. The added $sSortingOrder parameter in _ArraySortInOrder() is the only additional difference when compared to the _ArraySortc() function's parameters. The $sSortingOrder parameter contains the sorting string. The ascending order is the individual characters from left to right in the sorting order string. Descending order is the $sSortingOrder string from right to left. The _ArrayMultiSort() function _ArrayMultiSort(ByRef $aArray, $sSort = '0a', $iStartRow = 0, $iEndRow = 0) _ArraySortc() and _ArraySortInOrder() are the two sorting functions used in the _ArrayMultiSort() function. The $sSort parameter is a string that contains comma separated column descriptors. The sorting order of the columns is the numeric value in each column descriptor from left to right. For other characters in each column descriptor see _ArrayMultiSort() function's header in the ArrayMultiSortCase.au3 UDF, and comments in the examples. Here is the UDF containing the functions used to sort arrays with case sensitivity, forced numeric sorting, and specified ordered sorting. ArrayMultiSortCase.au3 #include-once ; https://www.autoitscript.com/forum/topic/198148-_arraymultisort-sort-multiple-columns-with-case-sensitivity/ ; File Name: #include <ArrayMultiSortCase.au3> ;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ; #INCLUDES# ========================================================================================================= #include <Array.au3> ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _ArrayMultiSort ; Description ...: Sort a 1D or, sort a 2D array with the ability to specify which columns to sort and which direction to sort for each column. ; Syntax.........: _ArrayMultiSort(ByRef $avArray[, $sSort = '0a'[, $iStartRow = 0[, $iEndRow = 0]]]) ; Parameters ....: $avArray - Array to sort ; $sSort - [optional] The default setting only sorts the first column, column 0, in ascending order. Otherwise, $sSort is ; a string made up of comma separated column descriptors which contains a column number, sort direction, case ; sensitivity, and make string numbers numeric, for that column. Each column descriptor shows the sort order of ; columns of the array from left to right. ; These 4 fields can be in any order in the column descriptor:- ; 1/ "0" or "1" etc - The column number(0 1 2 ...) - Col#0 is the first column - zero-based; ; 2/ "a" - Ascending order (Without "a" or "d" default is "a"); or, ; "d" - Descending order; And, ; 3/ "c" - sort that column with case sensitivity - Ascending (0-9,A-Z,a-z,Ordered sorting) or, ; Without "c" present, that column is sorted with case insensitivity (default). ; Sorting with case insensitivity - Ascending (Ordered sorting,9-0,Aa-Zz) ; 4/ "n" - Force sorting all digits present in that column numerically. ; Without "n" and digits that are stored as a string will be sorted alphabetically. ; Digits stored as numbers will automatically be sorted numerically in that column. ; 5/ "(Characters used in sorting order)" - A string of characters contained within brckets that give the ; ascending sorting order ; Within the column descriptors, spaces are optional; and, ; Upper or lower case column descriptors, "CAD" or "cad", are recognized as the same - use either (except within the sorting order string). ; Examples of the $sSort variable:- ; "3 ac, ND2, 0n(bac), d1" -> First sort col#3 (case sensitive, ascending, digits as strings sorted alphabetically[default]). ; Secondly sort col#2 (case insensitive, descending, digits sorted numerically.). ; Thirdly sort col#0 (case insensitive[default], ascending[default], digits sorted numerically, ; sort the characters between the brackets, "bac" in this column in the order "b then "a" then "c"). ; Lastly sort col#1 (case insensitive[default], descending, digits as strings ; sorted alphabetically[default]). ; "0" or "" -> Sort col#0 (case insensitive[default], ascending[default], digits as strings ; sorted alphabetically[default]) ; See https://www.autoitscript.com/forum/topic/198148-_arraysort-_arraymultisort-with-case-sensitivity/?do=findComment&comment=1422656 ; $iStartRow - [optional] Row index of array to start sorting at. ; $iEndRow - [optional] Row index of array to stop sorting at. ; Return values .: Success - 1 ; Failure - 0, @error set to the same as returned from _ArraySort() function. (See _ArraySort in AutoIt help file) ; Author ........: Malkey ; Modified.......: ; Remarks .......: Updated version from https://www.autoitscript.com/forum/topic/166426-_filelisttoarray-sorting/?do=findComment&comment=1216234 ; This function requires the __TestExp function, and #Include <Array.au3> and the case sensitive versions of _ArraySort, ; __ArrayQuickSort1D, and __ArrayQuickSort2D. ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _ArrayMultiSort(ByRef $aArray, $sSort = '0a', $iStartRow = 0, $iEndRow = 0) Local $iCol1, $Dir, $iLastRow, $iStart, $iRetV, $iEnd, $Err, $aSort2D[0][3] ;------------ $sSort (string) to $aSort2D (array) ----------- Local $aTempSort = StringSplit($sSort, ",", 2) ; $STR_NOCOUNT (2) Local $aSort2D[UBound($aTempSort)][5] For $i = 0 To UBound($aTempSort) - 1 $aSort2D[$i][4] = StringRegExp($aTempSort[$i], "\(.+?\)") ? StringRegExpReplace($aTempSort[$i], "^.*\(([^\)]+?)\).*$", "$1") : 0 ; Sorting to order $aTempSort[$i] = StringRegExpReplace($aTempSort[$i], "(\([^\)]+?\))", "") $aSort2D[$i][0] = StringInStr($aTempSort[$i], "c") ? 1 : 0 ; Case sensitivity $aSort2D[$i][1] = StringRegExp($aTempSort[$i], "\d+") ? StringRegExp($aTempSort[$i], "\d+", 1)[0] : 0 ; Column number $aSort2D[$i][2] = StringInStr($aTempSort[$i], "d") ? 1 : 0 ; Ascending/Decending sort order $aSort2D[$i][3] = StringInStr($aTempSort[$i], "n") ? 1 : 0 ; Numeric sorting Next ;_ArrayDisplay($aSort2D, "New method", "", 0, Default, "Case|Col#|Asc/Desc|Numeric|Sorting Order") ; ------------------------------------------------------------ If $iEndRow = 0 Or ($iEndRow > (UBound($aArray) - 1)) Then $iLastRow = UBound($aArray) - 1 $iStart = -1 $iEnd = -1 ; Sort the first column to be sorted. If IsString($aSort2D[0][4]) Then _ArraySortInOrder($aArray, $aSort2D[0][4], $aSort2D[0][2], $iStartRow, $iLastRow, Number($aSort2D[0][1]), 0, $aSort2D[0][0], $aSort2D[0][3]) Else _ArraySortC($aArray, $aSort2D[0][2], $iStartRow, $iLastRow, Number($aSort2D[0][1]), 0, $aSort2D[0][0], $aSort2D[0][3]) ; Sort on the first column (stored in $aSort2D[0][1]) EndIf ; Sort all remaining columns. For $j = 1 To UBound($aSort2D) - 1 ; For each group of equal values in the previous sorted column, sort the present column values on the same rows of each group. $iStart = -1 For $i = $iStartRow To $iLastRow Switch $i Case $iStartRow If $i <> $iLastRow Then If __TestExp($aArray, $aSort2D, $i, $j) Then $iStart = $i + 1 $iEnd = $i + 1 Else $iStart = $i $iEnd = $i + 1 EndIf EndIf Case $iLastRow $iEnd = $iLastRow If $iStart <> $iEnd Then If IsString($aSort2D[$j][4]) Then _ArraySortInOrder($aArray, $aSort2D[$j][4], $aSort2D[$j][2], $iStart, $iEnd, Number($aSort2D[$j][1]), 0, $aSort2D[$j][0], $aSort2D[$j][3]) Else _ArraySortC($aArray, $aSort2D[$j][2], $iStart, $iEnd, Number($aSort2D[$j][1]), 0, $aSort2D[$j][0], $aSort2D[$j][3]) EndIf EndIf Case Else If __TestExp($aArray, $aSort2D, $i, $j) Then $iEnd = $i If $iStart <> $iEnd Then If IsString($aSort2D[$j][4]) Then _ArraySortInOrder($aArray, $aSort2D[$j][4], $aSort2D[$j][2], $iStart, $iEnd, Number($aSort2D[$j][1]), 0, $aSort2D[$j][0], $aSort2D[$j][3]) Else _ArraySortC($aArray, $aSort2D[$j][2], $iStart, $iEnd, Number($aSort2D[$j][1]), 0, $aSort2D[$j][0], $aSort2D[$j][3]) EndIf EndIf $iStart = $i + 1 $iEnd = $iStart Else $iEnd = $i EndIf EndSwitch Next Next Return SetError($Err, 0, $iRetV) EndFunc ;==>_ArrayMultiSort ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __TestExp ; Description ...: Creates and tests a test expression. Internally used function by the _ArrayMultiSort() function ; Syntax.........: __TestExp($aA, $aC, $k, $m) ; Parameters ....: $aA - The 2D array to be sorted. ; $aC - A 2D array containing to column sorting order and each column's direction of sorting.(See Modified note) ; $k - The array's row index of the data being sorted. ; $m - The array's row index of the current column being sorted ; Return values .: 1 - When any of the created test expressions are true; or, ; 0 - When all of the created test expressions are false. ; Author ........: Malkey ; Modified.......: Malkey 2019/3/9 Array $aC is now [n][3] where [n][0] is case sensitivity; [n][1] is Column#; [n][2] is sort asc or desc. ; Remarks .......: This function is used internally by the _ArrayMultiSort function. The created expression tests the particular ; row, $k, of the test data, for each previously sorted column, $m -1, wheather the value in that column, $aA[$k][$aC[$w][1]], ; is not equal to the next value in that same column, $aA[$k + 1][$aC[$w][1]], where $aC[$w][1] contains the previously sorted column number. ; =============================================================================================================================== Func __TestExp(ByRef $aA, ByRef $aC, $k, $m) For $w = 0 To $m - 1 If ($aA[$k + 1][$aC[$w][1]]) <> ($aA[$k][$aC[$w][1]]) Then ; Like an "Or" join statements. If just one of the expressions in the For-Next loop is true, then function returns "1" (True). Return 1 EndIf Next Return 0 EndFunc ;==>__TestExp ; Description - This function sorts a 1D or 2D array, $array, in the order of the characters listed in a given string, $sSortingOrder. ; Parameters: ; $array - A 1D or 2D array to be sorted. ; $sSortingOrder - A string containing characters giving the ascending sorting order (left to right) of the same characters which appear in the array. ; $iDescending, $iStartRow, $iEndRow, $iSubItem, $iPivot - are the same parameters as in _ArraySort(), AutoIt's UDF function. ; $iCase - 0 (default) Upper and lower case are treated as the same. ; - 1 Upper and lower case are sorted separately. ; $iNumericalSort - 0 (default) If the number elements of an array are strings, these numbers are sorted alphabetically (lexicographically). ; Where one one, "11", is less than two, "2". ; - 1 Sorted in numerical order. Where two, 2, is less than eleven, 11. ; Requirement: #include <Array.au3> ; Returns: A sorted array. ; Remarks: Updated version from https://www.autoitscript.com/forum/topic/129312-an-array-or-string-sort-in-a-specific-order/ ; Func _ArraySortInOrder(ByRef $array, $sSortingOrder, $iDescending = 0, $iStartRow = 0, $iEndRow = 0, $iSubItem = 0, $iPivot = 0, $iCase = 0, $iNumericalSort = 0) Local $aOrder = StringSplit($sSortingOrder, "", 2) If $iEndRow = 0 Then $iEndRow = UBound($array) - 1 Switch UBound($array, 0) Case 1 ; --- Convert all characters in each element of $array, into an padded index number of the same character of the $sSortingOrder array, $aOrder. --- For $i = $iStartRow To $iEndRow $aItem = StringSplit($array[$i], "", 2) For $j = 0 To UBound($aItem) - 1 $iIndex = StringInStr($sSortingOrder, $aItem[$j], 1) If $iIndex Then $array[$i] = StringRegExpReplace($array[$i], "(?<!~)\Q" & $aItem[$j] & "\E(?!#>)", "~" & StringRight("00" & ($iIndex - 1), 3) & "#>") Next Next ; ------- Sort modified array, $array. ---------- _ArraySortC($array, $iDescending, $iStartRow, $iEndRow, $iSubItem, $iPivot, $iCase, $iNumericalSort) ;_ArrayDisplay($array, "Sorted 1D Array") ; ------- Convert back to original characters -------- For $i = $iStartRow To $iEndRow $array[$i] = Execute('"' & StringRegExpReplace($array[$i], "~(\d{3})#>", '"&$aOrder[$1]&"') & '"') Next Case 2 ; --- Convert all characters in each element of the selected column of the $array, into an padded index number of the same character of the $sSortingOrder array, $aOrder. --- For $i = $iStartRow To $iEndRow $aItem = StringSplit($array[$i][$iSubItem], "", 2) For $j = 0 To UBound($aItem) - 1 $iIndex = StringInStr($sSortingOrder, $aItem[$j], 1) If $iIndex Then $array[$i][$iSubItem] = StringRegExpReplace($array[$i][$iSubItem], "(?<!~)\Q" & $aItem[$j] & "\E(?!\d{0,2}#>)", "~" & StringRight("00" & ($iIndex - 1), 3) & "#>") Next Next ; ------- Sort modified array, $array on selected column. ---------- _ArraySortC($array, $iDescending, $iStartRow, $iEndRow, $iSubItem, $iPivot, $iCase, $iNumericalSort) ;_ArrayDisplay($array, "Sorted 2D Array") ; ------- Convert back to original characters -------- For $i = $iStartRow To $iEndRow $array[$i][2] = Execute('"' & StringRegExpReplace($array[$i][2], "~(\d{3})#>", '"&$aOrder[$1]&"') & '"') Next EndSwitch EndFunc ;==>_ArraySortInOrder ; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ; =============================================================================================== ; The following three function, ; _ArraySortC, __ArrayQuickSort1DC, and __ArrayQuickSort2DC are modied copies of the functions, ; _ArraySort, __ArrayQuickSort1D, and __ArrayQuickSort2D from the Array.au3 include file. ; The modifications allow optiomal case sensitive sorting and optional numeric sorting of arrays. ; _ArraySortC is compatiable with _ArraySort when not using the optional parameters for case ; sensitivity and numeric sorting in the _ArraySortC function. ; =============================================================================================== ; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ; #FUNCTION# ==================================================================================================================== ; Author ........: Jos ; Modified.......: LazyCoder - added $iSubItem option; Tylo - implemented stable QuickSort algo; Jos - changed logic to correctly Sort arrays with mixed Values and Strings; Melba23 - implemented stable pivot algo; Malkey - added optional case sensitive & optional numeric sorting. ; =============================================================================================================================== Func _ArraySortC(ByRef $aArray, $iDescending = 0, $iStart = 0, $iEnd = 0, $iSubItem = 0, $iPivot = 0, $iCase = 0, $iNumericalSort = 0) If $iDescending = Default Then $iDescending = 0 If $iStart = Default Then $iStart = 0 If $iEnd = Default Then $iEnd = 0 If $iSubItem = Default Then $iSubItem = 0 If $iPivot = Default Then $iPivot = 0 If $iCase = Default Then $iCase = 0 If Not IsArray($aArray) Then Return SetError(1, 0, 0) Local $iUBound = UBound($aArray) - 1 If $iUBound = -1 Then Return SetError(5, 0, 0) ; Bounds checking If $iEnd = Default Then $iEnd = 0 If $iEnd < 1 Or $iEnd > $iUBound Or $iEnd = Default Then $iEnd = $iUBound If $iStart < 0 Or $iStart = Default Then $iStart = 0 If $iStart > $iEnd Then Return SetError(2, 0, 0) ; Sort Switch UBound($aArray, $UBOUND_DIMENSIONS) Case 1 If $iNumericalSort Then ; <======== Optional numeric sorting 1D. For $i = $iStart To $iEnd If StringRegExp($aArray[$i], "^[+-]?\d+\.?\d*$") Then $aArray[$i] = Number($aArray[$i]) Next EndIf If $iPivot Then ; Switch algorithms as required __ArrayDualPivotSort($aArray, $iStart, $iEnd) Else __ArrayQuickSort1DC($aArray, $iStart, $iEnd, $iCase) EndIf If $iDescending Then _ArrayReverse($aArray, $iStart, $iEnd) Case 2 If $iNumericalSort Then ; <======== Optional numeric sorting 2D. For $i = $iStart To $iEnd If StringRegExp($aArray[$i][$iSubItem], "^[+-]?\d+\.?\d*$") Then $aArray[$i][$iSubItem] = Number($aArray[$i][$iSubItem]) Next EndIf If $iPivot Then Return SetError(6, 0, 0) ; Error if 2D array and $iPivot Local $iSubMax = UBound($aArray, 2) - 1 ; $UBOUND_COLUMNS (2) If $iSubItem > $iSubMax Then Return SetError(3, 0, 0) If $iDescending Then $iDescending = -1 Else $iDescending = 1 EndIf __ArrayQuickSort2DC($aArray, $iDescending, $iStart, $iEnd, $iSubItem, $iSubMax, $iCase) Case Else Return SetError(4, 0, 0) EndSwitch Return 1 EndFunc ;==>_ArraySortC ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __ArrayQuickSort1DC (Appended 'C' for case sensitivity) ; Description ...: Helper function for sorting 1D arrays ; Syntax.........: __ArrayQuickSort1D ( ByRef $aArray, ByRef $iStart, ByRef $iEnd ) ; Parameters ....: $aArray - Array to sort ; $iStart - Index of array to start sorting at ; $iEnd - Index of array to stop sorting at ; Return values .: None ; Author ........: Jos van der Zande, LazyCoder, Tylo, Ultima ; Modified.......: Malkey ; Remarks .......: For Internal Use Only. All StringCompare functions have $iCase parameter added for optional case sensitivity. ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func __ArrayQuickSort1DC(ByRef $aArray, Const ByRef $iStart, Const ByRef $iEnd, Const ByRef $iCase) If $iEnd <= $iStart Then Return Local $vTmp ; InsertionSort (faster for smaller segments) If ($iEnd - $iStart) < 15 Then Local $vCur For $i = $iStart + 1 To $iEnd $vTmp = $aArray[$i] If IsNumber($vTmp) Then For $j = $i - 1 To $iStart Step -1 $vCur = $aArray[$j] ; If $vTmp >= $vCur Then ExitLoop If ($vTmp >= $vCur And IsNumber($vCur)) Or (Not IsNumber($vCur) And StringCompare($vTmp, $vCur, $iCase) >= 0) Then ExitLoop $aArray[$j + 1] = $vCur Next Else For $j = $i - 1 To $iStart Step -1 If (StringCompare($vTmp, $aArray[$j], $iCase) >= 0) Then ExitLoop $aArray[$j + 1] = $aArray[$j] Next EndIf $aArray[$j + 1] = $vTmp Next Return EndIf ; QuickSort Local $L = $iStart, $R = $iEnd, $vPivot = $aArray[Int(($iStart + $iEnd) / 2)], $bNum = IsNumber($vPivot) Do If $bNum Then ; While $aArray[$L] < $vPivot While ($aArray[$L] < $vPivot And IsNumber($aArray[$L])) Or (Not IsNumber($aArray[$L]) And StringCompare($aArray[$L], $vPivot, $iCase) < 0) $L += 1 WEnd ; While $aArray[$R] > $vPivot While ($aArray[$R] > $vPivot And IsNumber($aArray[$R])) Or (Not IsNumber($aArray[$R]) And StringCompare($aArray[$R], $vPivot, $iCase) > 0) $R -= 1 WEnd Else While (StringCompare($aArray[$L], $vPivot, $iCase) < 0) $L += 1 WEnd While (StringCompare($aArray[$R], $vPivot, $iCase) > 0) $R -= 1 WEnd EndIf ; Swap If $L <= $R Then $vTmp = $aArray[$L] $aArray[$L] = $aArray[$R] $aArray[$R] = $vTmp $L += 1 $R -= 1 EndIf Until $L > $R __ArrayQuickSort1DC($aArray, $iStart, $R, $iCase) __ArrayQuickSort1DC($aArray, $L, $iEnd, $iCase) EndFunc ;==>__ArrayQuickSort1DC ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __ArrayQuickSort2DC (Appended 'C' for case sensitivity) ; Description ...: Helper function for sorting 2D arrays ; Syntax.........: __ArrayQuickSort2D ( ByRef $aArray, ByRef $iStep, ByRef $iStart, ByRef $iEnd, ByRef $iSubItem, ByRef $iSubMax ) ; Parameters ....: $aArray - Array to sort ; $iStep - Step size (should be 1 to sort ascending, -1 to sort descending!) ; $iStart - Index of array to start sorting at ; $iEnd - Index of array to stop sorting at ; $iSubItem - Sub-index to sort on in 2D arrays ; $iSubMax - Maximum sub-index that array has ; $iCase - ; Return values .: None ; Author ........: Jos van der Zande, LazyCoder, Tylo, Ultima ; Modified.......: Malkey ; Remarks .......: For Internal Use Only. All StringCompare functions have $iCase parameter added for optional case sensitivity. ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func __ArrayQuickSort2DC(ByRef $aArray, Const ByRef $iStep, Const ByRef $iStart, Const ByRef $iEnd, Const ByRef $iSubItem, Const ByRef $iSubMax, Const ByRef $iCase) If $iEnd <= $iStart Then Return ; QuickSort Local $vTmp, $L = $iStart, $R = $iEnd, $vPivot = $aArray[Int(($iStart + $iEnd) / 2)][$iSubItem], $bNum = IsNumber($vPivot) Do If $bNum Then ; While $aArray[$L][$iSubItem] < $vPivot While ($iStep * ($aArray[$L][$iSubItem] - $vPivot) < 0 And IsNumber($aArray[$L][$iSubItem])) Or (Not IsNumber($aArray[$L][$iSubItem]) And $iStep * StringCompare($aArray[$L][$iSubItem], $vPivot, $iCase) < 0) $L += 1 WEnd ; While $aArray[$R][$iSubItem] > $vPivot While ($iStep * ($aArray[$R][$iSubItem] - $vPivot) > 0 And IsNumber($aArray[$R][$iSubItem])) Or (Not IsNumber($aArray[$R][$iSubItem]) And $iStep * StringCompare($aArray[$R][$iSubItem], $vPivot, $iCase) > 0) $R -= 1 WEnd Else While ($iStep * StringCompare($aArray[$L][$iSubItem], $vPivot, $iCase) < 0) $L += 1 WEnd While ($iStep * StringCompare($aArray[$R][$iSubItem], $vPivot, $iCase) > 0) $R -= 1 WEnd EndIf ; Swap If $L <= $R Then For $i = 0 To $iSubMax $vTmp = $aArray[$L][$i] $aArray[$L][$i] = $aArray[$R][$i] $aArray[$R][$i] = $vTmp Next $L += 1 $R -= 1 EndIf Until $L > $R __ArrayQuickSort2DC($aArray, $iStep, $iStart, $R, $iSubItem, $iSubMax, $iCase) __ArrayQuickSort2DC($aArray, $iStep, $L, $iEnd, $iSubItem, $iSubMax, $iCase) EndFunc ;==>__ArrayQuickSort2DC Here are examples. #include <ArrayMultiSortCase.au3> ; --------------- Create test data -------------- Global $array[2000][5] = [["Col 0", "Col 1", "Col 2", "Col 3", "Col 4"]] ; For $i = 1 To UBound($array) - 1 $array[$i][0] = (Random(0, 1, 1) ? Chr(Random(97, 99, 1)) : Chr(Random(65, 67, 1))) ; Random lower case and upper case a,b, or, c. $array[$i][1] = (Random(0, 1, 1) ? Chr(Random(97, 99, 1)) : Chr(Random(65, 67, 1))) ; Random lower case and upper case a,b, or, c. $array[$i][2] = String(Random(0, 1, 1) ? Int(Random(0, 2, 1) & Random(0, 3, 1)) : (Random(0, 1, 1) ? Chr(Random(97, 99, 1)) : Chr(Random(65, 67, 1)))) ; Random lower case and upper case a,b, or, c. And random string numbers. $array[$i][3] = String(Random(0, 2, 1) & Random(1, 3, 1)) ; Random string numbers $array[$i][4] = Random(0, 20, 1) ; Random numeric numbers Next ; -----------> End of Create test data ----------- ; ---------------------------------------------------- Examples --------------------------------------------------------------- ; ======== _ArrayMultiSort() - 2D array ========= Local $aArray = $array ; Sort column 0(asc+case sensitive) then column 1(desc+case insensitive), then column 2(asc+case sensitive), ; then column 3(desc+case insensitive, numeric sorting), and lastly column 4(asc+case insensitive). ; _ArrayMultiSort(ByRef $aArray, $sSort = '0a', $iStartRow = 0, $iEndRow = 0) _ArrayMultiSort($aArray, "0a,c1d, 2 an(bacdefghijnmlosprqtuwxyzBA),3n,4d", 1) ; _ArrayDisplay($aArray, "Sorted 0a,1cd,2an(bacdefghijnmlosprqtuwxyzBA),3an,4d") #cs ; Note:- Colunm #0 - 1st sorted, ascending, case insenitive, digits not specifically numberfied. The string digits one one, "11", is smaller than the string digit "2" because of alphabetic sorting. See A's and a's mixed together because of case insenitivity. Colunm #1 - 2nd sorted, descending, case senitive, digits not specifically numberfied. See all c's are followed by all b's. c's and C's are separated because of case senitivity. Colunm #2 - 3rd sorted, ascending, incase insenitive. string digits numberfied. The number 2, is smaller than the number eleven, 11 when numerically sorted. All the characters in the array will be sorted in the ascending order (left to right) same as the characters between the brackets are listed. Colunm #3 - 4th sorted, ascending, case insenitive, numeric sorting of converted string numbers. Colunm #4 - Last sorted,descending, case insenitive, automatic numeric sorting of existing numeric values - No "n" necessary. In _ArrayDisplay, find the same two to four equal numbers in column #3. Note, in the corresponding rows in column #4, these two to four numbers are descending and numerically sorted. #ce ; ---------------------------------------------------------------------------------------------------------------------------- ; ======== _ArrayMultiSort() - 1D array ========= Local $aTest[] = [33, "Bmw", "Blue", 3.9, "brown", 11, "Clear", "green", 13, "Gray", -3.5, "gold", 23, "-3.1", "Gold", "3.7", "qqqqq", _ "0", "gray", "2", "ppppp", "3.3", "rrrrr", "3", "Royal", "112", "sssss", "42", "ace", "32", "White", "-112", "Yellow", "5"] ; _ArrayMultiSort(ByRef $aArray, $sSort = '0a', $iStartRow = 0, $iEndRow = 0) _ArrayMultiSort($aTest) _ArrayDisplay($aTest, "Sorted 0a") #cs ; Note:- Colunm #0 - Ascending - The numeric values are sorted numerically from smallest to largest. However, the string numbers are sorted alphabetically and interspersed between the numerically sorted values. And because of case insensitivity, the words starting with "G" and "g" are sorted as though the same letter. #ce ; ---------------------------------------------------------------------------------------------------------------------------- ; ======= _ArraySortInOrder() ========= Local $aTest[] = [33, "Bmw", "Blue", 3.9, "brown", 11, "Clear", "green", 13, "Gray", -3.5, "gold", 23, "-3.1", "Gold", "3.7", "qqqqq", _ "0", "gray", "2", "ppppp", "3.3", "rrrrr", "3", "Atlas", "112", "sssss", "42", "ace", "32", "White", "-112", "Yellow", "5", "kind"] ;_ArraySortInOrder(ByRef $array, $sSortingOrder, $iDescending = 0, $iStartRow = 0, $iEndRow = 0, $iSubItem = 0, $iPivot = 0, $iCase = 0, $iNumericalSort = 0) _ArraySortInOrder($aTest, "bacdefghijnmlosprqtuwxyzBA", 0, 0, 0, 0, 0, 0, 1) _ArrayDisplay($aTest, "Ordered sorting & numeric sorting") #cs Note:- Sorting with case sensitivity - Ascending (0-9,A-Z,a-z,Ordered sorting) Sorting with case insensitivity - Ascending (Ordered sorting,9-0,Aa-Zz) Colunm #0 - Case insensitive, Ascending, and Numerically sorted, and Ordered sorting - All numbers are forced to numeric values and sorted numerically from smallest number to largest number. #ce ; ---------------------------------------------------------------------------------------------------------------------------- ; ======= _ArraySortc() - numeric sorting ========= Local $aTest[18][2] = [["Color", "#"], ["Black", "a"], ["Blue", "13"], ["white", "23"], ["Brown", "-4.2"], ["Clear", "33"], ["Gold", "43"], ["gold", "53"], _ ["green", "c"], ["Green", "73"], ["brown", "-4.1"], ["Purple", "b"], ["Red", "93"], ["Royal", "+5"], ["Silver", "2"], ["Sky", "12"], ["White", "3"], ["Yellow", "5"]] $aTest1 = $aTest ; _ArraySortC(ByRef $aArray, $iDescending = 0, $iStart = 0, $iEnd = 0, $iSubItem = 0, $iPivot = 0, $iCase = 0, $iNumericalSort = 0) _ArraySortc($aTest1, 0, 1, 0, 1, 0, 0, 1) _ArrayDisplay($aTest1, "_ArraySortc()") ; Or ; ======= _ArraySort() - numeric sorting ========= $aTest2 = $aTest ; _ArrayNumbertizeForSort(ByRef $aArray, $iSubItem = 0, $iStart = 0, $iEnd = 0) _ArrayNumbertizeForSort($aTest2, 1, 1, 0) ; For use with current _ArraySort() function to numeric sort. ; _ArraySort ( ByRef $aArray [, $iDescending = 0 [, $iStart = 0 [, $iEnd = 0 [, $iSubItem = 0 [, $iPivot = 0]]]]] ) _ArraySort($aTest2, 0, 1, 0, 1) _ArrayDisplay($aTest2, "_ArrayNumbertizeForSort()") ; _ArrayNumbertizeForSort() used only here, in this above example. (not in UDF) ; $iSubItem [optional] Sub-index to sort on in 2D arrays (default 0 = first column) Func _ArrayNumbertizeForSort(ByRef $aArray, $iSubItem = 0, $iStart = 0, $iEnd = 0) If $iEnd = 0 Then $iEnd = UBound($aArray) - 1 Switch UBound($aArray, 0) Case 1 ; 1D array For $i = $iStart To $iEnd If StringRegExp($aArray[$i], "^[+-]?\d+\.?\d*$") Then $aArray[$i] = Number($aArray[$i]) Next Case 2 ; 2D array For $i = $iStart To $iEnd If StringRegExp($aArray[$i][$iSubItem], "^[+-]?\d+\.?\d*$") Then $aArray[$i][$iSubItem] = Number($aArray[$i][$iSubItem]) Next EndSwitch EndFunc ;==>_ArrayNumbertizeForSort
  11. Im trying to iterate through a 2d array created by ProcessList() function that returns a 2d array containing names and pid's, i wanted to filter through the names and delete entries that have "svchost.exe" and this is how i did it Func _Sanitize($array) For $x = 1 To UBound($array) - 1 ConsoleWrite($array[$x][0] & @CRLF) If $array[$x][0] == "svchost.exe" Then _ArrayDelete($array, $x) EndIf Next EndFunc ;==>_Sanitize And i get this error message What is wrong?
  12. Hello Guys! I wanted to share all my knowledge on arrays! Hope may enjoy the article , Lets start! Declaring arrays! Declaring arrays is a little different than other variables: ; Rules to follow while declaring arrays: ; ; Rule #1: You must have a declarative keyword like Dim/Global/Local before the declaration unless the array is assigned a value from a functions return (Ex: StringSplit) ; Rule #2: You must declare the number of dimensions but not necessarily the size of the dimension if you are gonna assign the values at the time of declaration. #include <Array.au3> Local $aEmptyArray[0] ; Creates an Array with 0 elements (aka an Empty Array). Local $aArrayWithData[1] = ["Data"] _ArrayDisplay($aEmptyArray) _ArrayDisplay($aArrayWithData) That's it Resizing Arrays Its easy! Just like declaring an empty array! ReDim is our friend here: #include <Array.au3> Local $aArrayWithData[1] = ["Data1"] ReDim $aArrayWithData[2] ; Change the number of elements in the array, I have added an extra element! $aArrayWithData[1] = "Data2" _ArrayDisplay($aArrayWithData) Just make sure that you don't use ReDim too often (especially don't use it in loops!), it can slow down you program. Best practice of using "Enum" You might be wondering what they might be... Do you know the Const keyword which you use after Global/Local keyword? Global/Local are declarative keywords which are used to declare variables, of course, you would know that already by now , If you check the documentation for Global/Local there is a optional parameter called Const which willl allow you to "create a constant rather than a variable"... Enum is similar to Const, it declares Integers (ONLY Integers): Global Enum $ZERO, $ONE, $TWO, $THREE, $FOUR, $FIVE, $SIX, $SEVEN, $EIGHT, $NINE ; And so on... ; $ZERO will evaluate to 0 ; $ONE will evaluate to 1 ; You get the idea :P ; Enum is very useful to declare Constants each containing a number (starting from 0) This script will demonstrate the usefulness and neatness of Enums : ; We will create an array which will contain details of the OS Global Enum $ARCH, $TYPE, $LANG, $VERSION, $BUILD, $SERVICE_PACK Global $aOS[6] = [@OSArch, @OSType, @OSLang, @OSVersion, @OSBuild, @OSServicePack] ; Now, if you want to access anything related to the OS, you would do this: ConsoleWrite(@CRLF) ConsoleWrite('+>' & "Architecture: " & $aOS[$ARCH] & @CRLF) ConsoleWrite('+>' & "Type: " & $aOS[$TYPE] & @CRLF) ConsoleWrite('+>' & "Langauge: " & $aOS[$LANG] & @CRLF) ConsoleWrite('+>' & "Version: " & $aOS[$VERSION] & @CRLF) ConsoleWrite('+>' & "Build: " & $aOS[$BUILD] & @CRLF) ConsoleWrite('+>' & "Service Pack: " & $aOS[$SERVICE_PACK] & @CRLF) ConsoleWrite(@CRLF) ; Isn't it cool? XD You can use this in your UDF(s) or Program(s), it will look very neat! Looping through an Array Looping through an array is very easy! . There are 2 ways to loop an array in AutoIt! Simple Way: ; This is a very basic way to loop through an array ; In this way we use a For...In...Next Loop! Global $aArray[2] = ["Foo", "Bar"] ; Create an array ; This loop will loop 2 times because our $aArray contains 2 elements. For $vElement In $aArray ; $vElement will contain the value of the elements in the $aArray... one element at a time. ConsoleWrite($vElement & @CRLF) ; Prints the element out to the console Next ; And that's it! Advanced Way: ; This is an advanced way to loop through an array ; In this way we use a For...To...Next Loop! Global $aArray[4] = ["Foo", "Bar", "Baz", "Quack"] ; Create an array ; This loop will loop 2 times because our $aArray contains 2 elements. For $i = 0 To UBound($aArray) - 1 ; $i is automatically created and is set to zero, UBound($aArray) returns the no. of elements in the $aArray. ConsoleWrite($aArray[$i] & @CRLF) ; Prints the element out to the console. Next ; This is the advanced way, we use $i to access the elements! ; With the advanced method you can also use the Step keyword to increase the offset in each "step" of the loop: ; This will only print every 2nd element starting from 0 ConsoleWrite(@CRLF & "Every 2nd element: " & @CRLF) For $i = 0 To UBound($aArray) - 1 Step 2 ConsoleWrite($aArray[$i] & @CRLF) Next ; This will print the elements in reverse order! ConsoleWrite(@CRLF & "In reverse: " & @CRLF) For $i = UBound($aArray) - 1 To 0 Step -1 ConsoleWrite($aArray[$i] & @CRLF) Next ; And that ends this section! For some reason, many people use the advance way more than the simple way . For more examples of loops see this post by @FrancescoDiMuro! Interpreting Multi-Dimensional Arrays Yeah, its the most brain squeezing problem for newbies, Imagining an 3D Array... I will explain it in a very simple way for ya, so stop straining you brain now! . This way will work for any array regardless of its dimensions... Ok, Lets start... You can imagine an array as a (data) mine of information: ; Note that: ; Dimension = Level (except the ground level :P) ; Element in a Dimension = Path ; Level 2 ----------\ ; Level 1 -------\ | ; Level 0 ----\ | | ; v v v Local $aArray[2][2][2] ; \-----/ ; | ; v ; Ground Level ; As you can see that $aArray is the Ground Level ; All the elements start after the ground level, i.e from level 0 ; Level 0 Contains 2 different paths ; Level 1 Contains 4 different paths ; Level 2 Contains 8 different paths ; When you want too fill some data in the data mine, ; You can do that like this: $aArray[0][0][0] = 1 $aArray[0][0][1] = 2 $aArray[0][1][0] = 3 $aArray[0][1][1] = 4 $aArray[1][0][0] = 5 $aArray[1][0][1] = 6 $aArray[1][1][0] = 7 $aArray[1][1][1] = 8 ; Don't get confused with the 0s & 1s, Its just tracing the path! ; Try to trace the path of a number with the help of the image! Its super easy! :D I hope you might have understand how an array looks, Mapping your way through is the key in Multi-Dimensional arrays, You take the help of notepad if you want! Don't be shy! Frequently Asked Questions (FAQs) & Their answers Q #1. What are Arrays? A. An Array is an datatype of an variable (AutoIt has many datatypes of variables like "strings", "integers" etc. Array is one of them). An Array can store information in a orderly manner. An Array consist of elements, each element can be considered as a variable (and yes, each element has its own datatype!). AutoIt can handle 16,777,216 elements in an Array, If you have an Array with 16,777,217 elements then AutoIt crashes. Q #2. Help! I get an error while declaring an Array!? A. You tried to declare an array like this: $aArray[1] = ["Data"] That is not the right way, Array is a special datatype, since its elements can be considered as individual variables you must have an declarative keyword like Dim/Global/Local before the declaration, So this would work: Local $aArray[1] = ["Data"] Q #3. How can I calculate the no. of elements in an array? A. The UBound function is your answer, Its what exactly does! If you have an multi-dimensional Array you can calculate the total no. of elements in that dimension by specifying the dimension in the second parameter of UBound Q #4. Why is my For...Next loop throwing an error while processing an Array? A. You might have done something like this: #include <MsgBoxConstants.au3> Local $aArray[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Local $iMyNumber = 0 For $i = 0 To UBound($aArray) ; Concentrate here! $iMyNumber += $aArray[$i] Next MsgBox($MB_OK, "Sum of all Numbers!", $iMyNumber) Did you notice the mistake? UBound returns the no. of elements in an array with the index starting from 1! That's right, you need to remove 1 from the total no. of elements in order to process the array because the index of an array starts with 0! So append a simple - 1 to the statment: #include <MsgBoxConstants.au3> Local $aArray[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Local $iMyNumber = 0 For $i = 0 To UBound($aArray) - 1 $iMyNumber += $aArray[$i] Next MsgBox($MB_OK, "Sum of all Numbers!", $iMyNumber) Q #5. Can an Array contain an Array? How do I access an Array within an Array? A. Yes! It is possible that an Array can contain another Array! Here is an example of an Array within an Array: ; An Array can contain another Array in one of its elements ; Let me show you an example of what I mean ;) #include <Array.au3> Global $aArray[2] $aArray[0] = "Foo" Global $aChildArray[1] = ["Bar"] $aArray[1] = $aChildArray _ArrayDisplay($aArray) ; Did you see that!? The 2nd element is an {Array} :O ; But how do we access it??? ; You almost guessed it, like this: ; Just envolope the element which contains the {Array} (as shown in _ArrayDisplay) with brackets (or parentheses)! :D ConsoleWrite(($aArray[1])[0]) ; NOTE the brackets () around $aArray[1]!!! They are required or you would get an syntax error! ; So this: $aArray[1][0] wont work! More FAQs coming soon!
  13. In every other language doing dim $a[3] = [1, 2, 3] $b = $a creates a reference to a but in autoit it always makes a copy. I didn't realize this until I have performance problems and now I'm trying to switch over to the reference behavior. How can I change the above statement so b is a reference to a and not a full copy?
  14. Hello, I am currently writing a program that parses a massive table from a website, and need a way to add a progress bar while parsing. I am currently using the function _IETableWriteToArray($oObj, True) to parse the array. I need the progress bar to update as the table is parsed, not just at the end of the parsing. Any help at all would be very much appreciated! *EDIT --> The array I am left with after parsing is $array[0-50000][16]
  15. Hello, So this may be more of a challenge of effective programming then specific to AutoIT but I want to solve this problem with AutoIT so i'm putting it here. (If someone has a better language to solve with I'm all ears) So the task I'm trying to achieve is that I have multiple .CSV files that have: year, month, day, hour, value. I need to be able to sum up all the values that have the same date/time, then find which date and time has the maximum value. The problem is that each file may or may not have same amount of days/hours as the rest. So I need to devise a way to handle this. Example: File A File B File C 2018 1 1 1:00 10 2018 1 1 2:00 10 2018 1 1 1:00 10 2018 1 1 2:00 12 2018 1 1 3:00 12 2018 1 2 1:00 12 2018 1 1 3:00 14 2018 1 1 4:00 14 2018 2 1 1:00 16 2018 2 1 1:00 16 2018 2 1 1:00 16 Answer I want to be spit out is Feb 1st 2018 at 2:00 with value of 48 So far I've got code to store all .CSV files to an array, then a loop to go through each csv, but not sure how to effectively manipulate the data. Keep in mind each file has over 7000 time entry points. If anyone can solve this that would be pretty awesome! #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> RefineData() Func RefineData() Local $i, $filenum, $file, $csvArray, $FilePath = @ScriptDir $fileList = _FileListToArrayRec($FilePath, "*.csv", 1) ;Create and array of all .csv files within folder Local $chkArray[UBound($fileList)][2] ;=====Loop through the .csv files within the folder====== For $filenum = 1 To UBound($fileList) - 1 Step 1 $file = $fileList[$filenum] $sFilePath = $FilePath & "\" & $file ;=====Create array based on csv file===== _FileReadToArray($sFilePath, $csvArray, $FRTA_NOCOUNT, ",") ;#### Operations here ###### next msgbox(0,"", "Date: " & $date_of_max & "Value: " & $maxVal );display solution endfunc
  16. Associative Array Functions I've seen a couple of UDFs for this on the forum. One of them I quite like. But it's still nearly not as good as this method, IMHO. I don't recall if I discovered the "Scripting.Dictionary" COM object myself or if I got the original base code from somewhere online. I have recently searched the web (and here) hard for any AutoIt references to this, other than my own over the years I've been using this (in ffe, etc..), and I can find nothing, so I dunno. If anyone does, I'd love to give credit where it's due; this is some cute stuff! It could actually be all my own work! lol At any rate, it's too useful to not have posted somewhere at autoitscript.com, so I've put together a wee demo. For those who haven't heard of the COM "Scripting.Dictionary".. If you've ever coded in Perl or PHP (and many other languages), you know how useful associative arrays are. Basically, rather than having to iterate through an array to discover it's values, with an associative array you simply pluck values out by their key "names". I've added a few functions over the years, tweaked and tuned, and this now represent pretty much everything you need to easily work with associative arrays in AutoIt. En-joy! The main selling point of this approach is its simplicity and weight. I mean, look at how much code it takes to work with associative arrays! The demo is bigger than all the functions put together! The other selling point is that we are using Windows' built-in COM object functions which are at least theoretically, fast and robust. I've used it many times without issues, anyhow, here goes.. ; Associative arrays in AutoIt? Hells yeah! ; Initialize your array ... global $oMyError = ObjEvent("AutoIt.Error", "AAError") ; Initialize a COM error handler ; first example, simple. global $simple AAInit($simple) AAAdd($simple, "John", "Baptist") AAAdd($simple, "Mary", "Lady Of The Night") AAAdd($simple, "Trump", "Silly Man-Child") AAList($simple) debug("It is said that Trump is a " & AAGetItem($simple, "Trump") & ".", @ScriptLineNumber);debug debug("") ; slightly more interesting.. $ini_path = "AA_Test.ini" ; Put this prefs section in your ini file.. ; [test] ; foo=foo value ; foo2=foo2 value ; bar=bar value ; bar2=bar2 value global $associative_array AAInit($associative_array) ; We are going to convert this 2D array into a cute associative array where we ; can access the values by simply using their respective key names.. $test_array = IniReadSection($ini_path, "test") for $z = 1 to 2 ; do it twice, to show that the items are *really* there! for $i = 1 to $test_array[0][0] $key_name = $test_array[$i][0] debug("Adding '" & $key_name & "'..");debug ; key already exists in "$associative_array", use the pre-determined value.. if AAExists($associative_array, $key_name) then $this_value = AAGetItem($associative_array, $key_name) debug("key_name ALREADY EXISTS! : =>" & $key_name & "<=" , @ScriptLineNumber);debug else $this_value = $test_array[$i][1] ; store left=right value pair in AA if $this_value then AAAdd($associative_array, $key_name, $this_value) endif endif next next debug(@CRLF & "Array Count: =>" & AACount($associative_array) & "<=" , @ScriptLineNumber);debug AAList($associative_array) debug(@CRLF & "Removing 'foo'..");debug AARemove($associative_array, "foo") debug(@CRLF & "Array Count: =>" & AACount($associative_array) & "<=" , @ScriptLineNumber);debug AAList($associative_array) debug(@CRLF & "Removing 'bar'..");debug AARemove($associative_array, "bar") debug(@CRLF & "Array Count: =>" & AACount($associative_array) & "<=" , @ScriptLineNumber);debug AAList($associative_array) quit() func quit() AAWipe($associative_array) AAWipe($simple) endfunc ;; Begin AA Functions func AAInit(ByRef $dict_obj) $dict_obj = ObjCreate("Scripting.Dictionary") endfunc ; Adds a key and item pair to a Dictionary object.. func AAAdd(ByRef $dict_obj, $key, $val) $dict_obj.Add($key, $val) If @error Then return SetError(1, 1, -1) endfunc ; Removes a key and item pair from a Dictionary object.. func AARemove(ByRef $dict_obj, $key) $dict_obj.Remove($key) If @error Then return SetError(1, 1, -1) endfunc ; Returns true if a specified key exists in the associative array, false if not.. func AAExists(ByRef $dict_obj, $key) return $dict_obj.Exists($key) endfunc ; Returns a value for a specified key name in the associative array.. func AAGetItem(ByRef $dict_obj, $key) return $dict_obj.Item($key) endfunc ; Returns the total number of keys in the array.. func AACount(ByRef $dict_obj) return $dict_obj.Count endfunc ; List all the "Key" > "Item" pairs in the array.. func AAList(ByRef $dict_obj) debug("AAList: =>", @ScriptLineNumber);debug local $k = $dict_obj.Keys ; Get the keys ; local $a = $dict_obj.Items ; Get the items for $i = 0 to AACount($dict_obj) -1 ; Iterate the array debug($k[$i] & " ==> " & AAGetItem($dict_obj, $k[$i])) next endfunc ; Wipe the array, obviously. func AAWipe(ByRef $dict_obj) $dict_obj.RemoveAll() endfunc ; Oh oh! func AAError() Local $err = $oMyError.number If $err = 0 Then $err = -1 SetError($err) ; to check for after this function returns endfunc ;; End AA Functions. ; debug() (trimmed-down version) ; ; provides quick debug report in your console.. func debug($d_string, $ln=false) local $pre ; For Jump-to-Line in Notepad++ if $ln then $pre = "(" & $ln & ") " & @Tab ConsoleWrite($pre & $d_string & @CRLF) endfunc ;o) Cor
  17. How do I work with 2D arrays. I've tried this but get errors. Local $aTest[4][4] = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]] ;$aTest[0][] = [10,11,12] ; Error at [] Local $sTest = "" For $i = 0 To UBound($aTest)-1 Local $aExtract = _ArrayExtract($aTest,$i,$i) $sTest = $sTest & MyTest($aExtract) Next Func MyTest($aTemp) _ArrayDisplay($aTemp) ; Error at v $aTemp Return String($aTemp[0]) & " - " & String($aTemp[1]) & " - " & String($aTemp[2]) & @CRLF EndFunc
  18. My esteemed Autoits I need your help once again. I'm trying to figure out how to create a loop that gets 1 value from an array and repeats until each value from the array has been used. I have never used arrays before and I know once I learn more things should get easier for me. Here is what Im trying to do: -Have an array of values that determine what application i log into. ex: app1, app2, app3, app4 etc. -Have a loop that repeats a process sequentially using each value in the array to finish the process for each app1, app2, app 3 and so forth. I have 30 apps that I need to update on a regular basis and getting this sorted out is what I perceive to be the best way to do it. Here is my feeble attempt that obviously fails: #include <msgboxconstants.au3> #include <Constants.au3> #include <array.au3> Login() Func Login() local $array[30] = ["10", "11", "12",etc etc] ;;Local $site = InputBox("ERx Site","What site do you want to login as?","","") Local $userid = InputBox("ERx Login", "What is your username?", "", "") Local $Passwd = InputBox("Security Check", "Enter your UAT password.", "", "*") for $1 = 1 to 30(I need to do the same steps in 30 different apps) run("Z:launch.exe") WinWaitActive("Input") Send (Sequential ARRAY VALUE HERE) Send("{ENTER}") WinWaitActive("window") Send($userid) Send("{TAB}") send($Passwd) Send("{ENTER}") WinWaitActive("[CLASS:SunAwtDialog]") Sleep(500) WinClose("Home Page") Next EndFunc your help is greatly appreciated. Thanks for your time
  19. Hi All, I am fairly new to AutoIT and I am still trying to learn, I have been using _FileListToArray to list all the files with a particular extension in an array and then loop through it for operation ( For $i = 1 To UBound($FileArray) - 1). So far this has been working fine. But I am not able to figure out a problem that I have; what if I have 50 files but I only want to loop through first 10 files and then next ten and so on? Or rather I should say, how I can I only feed max 10 files to the array at a time when I do _FileListToArray regardless of the total number of files in the folder? Any insight/help will be much appreciated
  20. I'm trying to get an array from a website so that I can just get the url, but I am not sure how. I read a bit of arrays but I have a feeling I'd have to be writing a lot more than what I should be. I will include the script I have so far and the API url for what I want. API: https://api.fast.com/netflix/speedtest?https=true&token=YXNkZmFzZGxmbnNkYWZoYXNkZmhrYWxm&urlCount=1 (I want the 'url' array that contains the url) Code: #include <MsgBoxConstants.au3> #include <Inet.au3> #include <Array.au3> $site = _INetGetSource('http://api.fast.com/netflix/speedtest?https=true&token=YXNkZmFzZGxmbnNkYWZoYXNkZmhrYWxm&urlCount=1') MsgBox($MB_SYSTEMMODAL, "Title", $site[1])
  21. Alright, currently I'm trying to merge two loops: Local $aArray[99][13] For $iLoop = 1 to 100 $aArray[$iLoop - 1][0] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration", $iLoop) If @error <> 0 Then ReDim $aArray[$iLoop - 1][13] ExitLoop EndIf Next For $iLoop1 = 0 to UBound($aArray, 1) - 1 For $iLoop2 = 1 to 12 $aArray[$iLoop1][$iLoop2] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\" & $aArray[$iLoop1][0], $iLoop2) If @error <> 0 Then ExitLoop Next Next into one. Here's what I have so far: Local $aArray[99][13] For $iLoop1 = 0 to UBound($aArray, 1) - 1 For $iLoop2 = 0 to 12 ConsoleWrite("Loop1 = " & $iLoop1 & ", Loop2 = " & $iLoop2 & @CRLF) If $iLoop2 = 0 Then $aArray[$iLoop1][0] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration", $iLoop1 + 1) If @error <> 0 Then ReDim $aArray[$iLoop1 + 1][13] ExitLoop EndIf Else $aArray[$iLoop1][$iLoop2] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\" & $aArray[$iLoop1][0], $iLoop2) If @error <> 0 Then ExitLoop EndIf Next Next And it keeps error-ing out trying to exceed the dimension range of the array. Does the Loop not recheck the size of the array after the original check or am I doing something else wrong. Thanks.
  22. Hi guys! How are you? Hope you're fine I'm trying to use SQLite for managing some data, and, I would like to display my "retrieved" data, but I'm trying to do a select from 2 table, and seems to not work properly... What I'd like to do is retrieve data from 2 tables and display in a listview... I tried with: Local $aRisultato, $iRighe, $iColonne, $iRVal $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Rockwell, Magazzino_Siemens;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then ;_SQLite_Display2DResult($aRisultato) _ArrayDisplay($aRisultato) EndIf ... but it displays a single record 41 times, and it does this thing for every record in the database... What do you need to help me? Thanks EDIT: Managed with a double If and double query like this: $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Rockwell;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then Local $aRisultatoRockwell = $aRisultato $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Siemens;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then _ArrayConcatenate($aRisultato, $aRisultatoRockwell) Local $i, $sRiga, $s_LV_Item For $i = 1 To Ubound($aRisultato) - 1 $sRiga = $aRisultato[$i][0] & "|" & _ $aRisultato[$i][1] & "|" & _ $aRisultato[$i][2] & "|" & _ $aRisultato[$i][3] & "|" & _ $aRisultato[$i][4] & "|" & _ $aRisultato[$i][5] & "|" & _ $aRisultato[$i][6] & "|" & _ $aRisultato[$i][7] & "|" & _ $aRisultato[$i][8] & "|" & _ $aRisultato[$i][9] & "|" & _ $aRisultato[$i][10] & "|" & _ $aRisultato[$i][11] $s_LV_Item = GUICtrlCreateListViewItem($sRiga, $lv_Lista) Next And so, the listview is created If anyone has another more efficient way, I'm here Thanks guys
  23. Hi people, It's been a while I have been scripting in vbscript for some time but now i'm back using AutoIt for a project: Scripting Adobe Illustrator with AutoIt . This vb code needs to be converted: Set appRef = CreateObject("Illustrator.Application") 'Create a new document and assign it to a variable Set documentRef = appRef.Documents.Add 'Create a new text frame item and assign it to a variable Set sampleText = documentRef.TextFrames.Add 'Set the contents and position of the TextFrame sampleText.Position = Array(200, 200) sampleText.Contents = "Hello World!" The ... = Array(200,200) part is done in one line in vb, is this possible in AutoIt without declaring an array first? I know I sound like a newbie but I never had to use arrays this way before.. what i have: $appRef = ObjCreate("Illustrator.Application") ;Create a new document and assign it to a variable $documentRef = $appRef.Documents.Add ;Create a new text frame item and assign it to a variable $sampleText = $documentRef.TextFrames.Add ;Set the contents and position of the TextFrame ReDim $sampleText.Position[2] = [200, 200] <<<--- doesn't work... $sampleText.Contents = "Hello World!"
  24. I just can't get my head around what I'm trying to do. Ok so I read all the links in a webpage into a 1D array, I then make the array unique as there are some duplicates. I then find all the entries I want from the array and put the number of the row for those entries into another 1D array. So I now have two arrays; one has unique links, the other has the numbers of the rows for the links I actually want. Using the second array I would like to amend the first array, or create a third, with just the links I actually want. Confused? Welcome to my world. I'll put the relevant section of code below to show where I am up to. I've left the _ArrayDisplay in the above code which I am using to check the code does what I wanted. So the above code works fine, I'm just stumped on how to extract the links from $aLinks that I want. $oLinks = _IELinkGetCollection($oIE) Local $aLinks[1] = ["Link"] For $oLink in $oLinks _ArrayAdd($aLinks, $oLink.href) Next ;_ArrayDisplay($aLinks) $aLinks = _ArrayUnique($aLinks) ;_ArrayDisplay($aLinks) $aLinksToClick = _ArrayFindAll($aLinks, "azref", 0, 0, 0, 3) ;_ArrayDisplay($aLinksToClick) Local $aSortedLinks[1] = ["Sorted Links"] For $i = 0 To UBound($aLinksToClick) - 1 $Blah = _ArrayExtract($aLinks, $aLinksToClick[$i], $aLinksToClick[$i]) _ArrayAdd($aSortedLinks, $Blah) Next
  25. I've been searching for a solution on the forum and came across a partial solution in this topic... My problem is that I have a 2D array; column one has the description (a string) of the integer in column two. I want to sort this array by the value of column two from highest to lowest. Only my _ArraySort produces a strange result. Here is the code and the output before and after... Local $PensionsOne = ($MonthlyPensionIncomeOne + $MonthlyPensionCreditIncomeOne) Local $SecondEmploymentOne = ($SecondSalaryOne + $SecondBonusOne + $SecondOvertimeOne + $SecondCommissionOne) Local $aGetHighestFiveAdditionalIncomesForAppOne[8][2] = [ _ ["Occupational pension income", $PensionsOne], _ ["2nd job", $SecondEmploymentOne], _ ["Working Tax Credits", $MonthlyUniversalTaxCreditIncomeOne], _ ["Disability living allowance", $MonthlyStateDisabilityIncomeOne], _ ["Investment or dividend income", $MonthlyInvestmentIncomeOne], _ ["Maintenance", $MonthlyMaintenanceIncomeOne], _ ["Rental income", $MonthlyUnencumberedRentalIncomeOne], _ ["Self-employed income", $SecondNetPreTaxProfitLatestYrOne]] _ArrayDisplay($aGetHighestFiveAdditionalIncomesForAppOne) _ArraySort($aGetHighestFiveAdditionalIncomesForAppOne, 0, 0, 2) _ArrayDisplay($aGetHighestFiveAdditionalIncomesForAppOne)
×
×
  • Create New...