Jump to content

Rotating values within an array [SOLVED]


Recommended Posts

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

 

Edited by TimRude
Link to post
Share on other sites

Here's an alternative using _ArrayPush --

#include <Array.au3>

Local $avArrayTarget[] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
_ArrayDisplay($avArrayTarget, "BEFORE rotation")
_ArrayRotate($avArrayTarget, 4)
_ArrayDisplay($avArrayTarget, "AFTER rotation")


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, 0, $iMakeFirst - 1)  
    Local $iResult = _ArrayPush($aArray, $aFirst)

    Return ($iResult = 1)
EndFunc

 

Link to post
Share on other sites
3 minutes ago, Nine said:

Maybe this one liner ? 

#include <Array.au3>

Local $avArrayTarget[] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
$arr = StringSplit(StringRegExpReplace(_ArrayToString($avArrayTarget), "(.*)\|(.+)", "$2\|$1"), "|", $STR_NOCOUNT)
_ArrayDisplay($arr)

 

This moves the last element to the beginning, but I don't know how you would use it to move an entire chunk of the array around. Perhaps in a loop? But then you end up doing a whole lot of converting array ==> string ==> array over and over again.

Link to post
Share on other sites

I took my method, Danp2's method, and pixelsearch's method and ran each of them on an array consisting of a list of all of the filenames (including paths) in the @SystemDir folder. On my Win10 machine, that ended up being an array with 2891 entries. With each method, I asked it to take the bottom half of the array and move it to the top, and then to do it again so that it ended up back where it began. (Well almost, since I had an odd number of entries it ends up with the originally last entry as the first entry when finished, but that's just due to rounding and it ends up exactly the same with each of the methods.)

For each method, I timed how long it took to do these 2 iterations using TimerInit and TimerDiff. I ran each test 5 times, but each run was in a new instance of the test app. In other words, after running each test, the script Exited. I then ran the script again for a fresh run each time. The times listed do not include the time populating the array with the filenames. They're only the time taken to actually move the elements around.

Results:

My method with _ArrayExtract and _ArrayConcatenate: Average 28.5886 ms -- the slowest of the three

@Danp2 Your method with _ArrayExtract and _ArrayPush: Average 25.5905 ms -- marginally faster than mine

@pixelsearch Your method using none of the _Array UDF functions: Average 12.4234 ms -- you blew our doors off 😁

 

Link to post
Share on other sites
Link to post
Share on other sites

@Nine One other slight glitch with your RegExp method: If any of the array elements contain a comma, it messes everything up since you're using a comma as your delimiter. I may have thrown you off with my simplified example of just digits, but in actual practice the array will contain text that very well might have commas in it. For example, maybe a list of names (Last, First), or address information.

It's probably possible to switch to a different (less common) delimiter, but even then there's no way to be positive that any character used as a delimiter would never possibly be part of the array contents. So I'm not sure there is a 100% safe way to do it using RegExp since the data in the array has to live as delimited text as part of the process.

But as you say, definitely a different way to approach the task. Certainly some clever outside the box thinking. 🧠

Link to post
Share on other sites
6 hours ago, TimRude said:

@Nine One other slight glitch with your RegExp method: If any of the array elements contain a comma, it messes everything up since you're using a comma as your delimiter. [...)but in actual practice the array will contain text that very well might have commas in it. For example, maybe a list of names (Last, First), or address information.

If we think of it that way, then the array may also contain the pipe character "|" which is also a delimiter in plenty of functions and will mess everything when a script uses it as delimiter, in case the pipe character is found inside strings.

Below are Nine's scripts (both editions he posted above), splitted to experiment and try to understand better the logic of his one-liner scripts. You can uncomment the #cs #ce parts in the scripts to run only the desired part (be lazy when you uncomment each block of #cs #ce, not greedy:D

At the very end of the scripts, a delimiter such as ChrW(63743) has been added, not sure you'll find it in usual strings. I think the only way to make sure a delimiter isn't part of the strings wouid be to check several characters (for example starting with ChrW(65535) then descending) so you'll make sure this "delimiter character" won't be found in the strings, but it may take some time if the array is huge.

1st edition (one part is already uncommented)

#cs
; Nine's original (1st edition) | delimiter
; =========================================
#include <Array.au3>

Local $avArrayTarget[] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
$arr = StringSplit(StringRegExpReplace( _
    _ArrayToString($avArrayTarget), "(.*)\|(.+)", "$2\|$1"), _
    "|", $STR_NOCOUNT)
_ArrayDisplay($arr)
#ce



; #cs
; 1st edition detailed: | delimiter
; ==================================
#include <Array.au3>

Local $avArrayTarget[] = ["100", "200", "300", "400", "500", "600", "700", "800", "900"]
_ArrayDisplay($avArrayTarget, "Array before")

Local $sString1 = _ArrayToString($avArrayTarget) ; default delimiter is |
ConsoleWrite("$sString1 = " & $sString1 & @crlf) ; "100|200|300|400|500|600|700|800|900"

Local $sString2 = StringRegExpReplace($sString1, "(.*)\|(.+)", "$2\|$1") ; as greedy, then (.+) or (.*)
ConsoleWrite("$sString2 = " & $sString2 & @crlf) ; "900|100|200|300|400|500|600|700|800"

Local $arr = StringSplit($sString2, "|", $STR_NOCOUNT)
_ArrayDisplay($arr, "Array after")
; #ce

2nd edition below (one part is already uncommented)

#cs
; Nine's original (2nd edition) comma delimiter
; =============================================
#include <Array.au3>
#include <String.au3>

Local $avArrayTarget[] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Local $iShift = 4
$arr = StringSplit(StringTrimRight(StringRegExpReplace( _
    _ArrayToString($avArrayTarget, ","), "(" & _StringRepeat(".*?,", $iShift) & ")(.+)", "$2,$1"), _
    1), _
    ",", $STR_NOCOUNT)
_ArrayDisplay($arr)
#ce



#cs
; 2nd edition detailed: comma delimiter
; =====================================
#include <Array.au3>
#include <String.au3>

Local $avArrayTarget[] = ["100", "200", "300", "400", "500", "600", "700", "800", "900"]
_ArrayDisplay($avArrayTarget, "Array before")

Local $iShift = 4
Local $sShift = _StringRepeat(".*?,", $iShift)
ConsoleWrite("$sShift = " & $sShift & @crlf) ; ".*?,.*?,.*?,.*?,"

Local $sString1 = _ArrayToString($avArrayTarget, ",")
ConsoleWrite("$sString1 = " & $sString1 & @crlf) ; "100,200,300,400,500,600,700,800,900"

Local $sString2 = StringRegExpReplace($sString1, "(" & $sShift & ")(.+)", "$2,$1") ; as greedy, then (.+) or (.*)
ConsoleWrite("$sString2 = " & $sString2 & @crlf) ; "500,600,700,800,900,100,200,300,400,"

Local $sString3 = StringTrimRight($sString2, 1)
ConsoleWrite("$sString3 = " & $sString3 & @crlf) ; "500,600,700,800,900,100,200,300,400"

Local $arr = StringSplit($sString3, ",", $STR_NOCOUNT)
_ArrayDisplay($arr, "Array after")
#ce



#cs
; 2nd edition detailed: | delimiter
; =================================
#include <Array.au3>
#include <String.au3>

Local $avArrayTarget[] = ["100", "200", "300", "400", "500", "600", "700", "800", "900"]
_ArrayDisplay($avArrayTarget, "Array before")

Local $iShift = 4
Local $sShift = _StringRepeat(".*?\|", $iShift)
ConsoleWrite("$sShift = " & $sShift & @crlf) ; ".*?\|.*?\|.*?\|.*?\|"

Local $sString1 = _ArrayToString($avArrayTarget) ; default delimiter is |
ConsoleWrite("$sString1 = " & $sString1 & @crlf) ; "100|200|300|400|500|600|700|800|900"

Local $sString2 = StringRegExpReplace($sString1, "(" & $sShift & ")(.+)", "$2\|$1") ; as greedy, then (.+) or (.*)
ConsoleWrite("$sString2 = " & $sString2 & @crlf) ; "500|600|700|800|900|100|200|300|400|"

Local $sString3 = StringTrimRight($sString2, 1)
ConsoleWrite("$sString3 = " & $sString3 & @crlf) ; "500|600|700|800|900|100|200|300|400"

Local $arr = StringSplit($sString3, "|", $STR_NOCOUNT)
_ArrayDisplay($arr, "Array after")
#ce



; #cs
; 2nd edition detailed: | delimiter without _StringRepeat but using RegEx {...} quantifier
; ========================================================================================
#include <Array.au3>

Local $iShift = 4

Local $avArrayTarget[] = ["100", "200", "300", "400", "500", "600", "700", "800", "900"]
_ArrayDisplay($avArrayTarget, "Array before")

Local $sString1 = _ArrayToString($avArrayTarget) ; default delimiter is |
ConsoleWrite("$sString1 = " & $sString1 & @crlf) ; "100|200|300|400|500|600|700|800|900"

Local $sString2 = StringRegExpReplace($sString1, "((?:.*?\|){" & $iShift & "})(.+)", "$2\|$1") ; as greedy, then (.+) or (.*)
ConsoleWrite("$sString2 = " & $sString2 & @crlf) ; "500|600|700|800|900|100|200|300|400|"

Local $sString3 = StringTrimRight($sString2, 1)
ConsoleWrite("$sString3 = " & $sString3 & @crlf) ; "500|600|700|800|900|100|200|300|400"

Local $arr = StringSplit($sString3, "|", $STR_NOCOUNT)
_ArrayDisplay($arr, "Array after")
; #ce



#cs
; 2nd edition detailed: ChrW(63743) delimiter without _StringRepeat but using RegEx {...} quantifier
; ==================================================================================================
#include <Array.au3>

Local $iShift = 4, $sSeparator = ChrW(63743)

Local $avArrayTarget[] = ["100", "200", "300", "400", "500", "600", "700", "800", "900"]
_ArrayDisplay($avArrayTarget, "Array before")

Local $sString1 = _ArrayToString($avArrayTarget, $sSeparator)
ConsoleWrite("$sString1 = " & $sString1 & @crlf)

Local $sString2 = StringRegExpReplace($sString1, "((?:.*?" &$sSeparator & "){" & $iShift & "})(.+)", "$2" & $sSeparator & "$1")
ConsoleWrite("$sString2 = " & $sString2 & @crlf)

Local $sString3 = StringTrimRight($sString2, 1)
ConsoleWrite("$sString3 = " & $sString3 & @crlf)

Local $arr = StringSplit($sString3, $sSeparator, $STR_NOCOUNT)
_ArrayDisplay($arr, "Array after")
#ce

 

9 hours ago, TimRude said:

@pixelsearch Your method using none of the _Array UDF functions: Average 12.4234 ms -- you blew our doors off

"to blow doors off" : thanks for teaching me this expression as english isn't my native language. Always great to learn something new :)

Edited by pixelsearch
typo
Link to post
Share on other sites
13 hours ago, TimRude said:

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

Leave the array alone and access its elements using an offset and Mod() the array size.

Local $aOrig = [0,1,2,3,4,5,6,7,8,9]

Func ArrOfs(ByRef $a, $iOfs, $iIdx)
    Return($a[Mod($iOfs + $iIdx, UBound($a))])
EndFunc

ConsoleWrite("New element of $aOrig at index 0 is " & ArrOfs($aOrig, 4, 0) & @LF)
ConsoleWrite("New element of $aOrig at index 7 is " & ArrOfs($aOrig, 4, 7) & @LF)

; if you really need to permanently change the array, elements index offset by $n:
Func ArrMove(ByRef $a, $n)
    Local $iSize = UBound($a)
    Local $b[$iSize]
    For $i = 0 To $iSize - 1
        $b[$i] = $a[Mod($i + $n, $iSize)]
    Next
    $a = $b
EndFunc

ArrMove($aOrig, 4)
_ArrayDisplay($aOrig)

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to post
Share on other sites

My version uses only ArrayToString, ArrayFromString and string functions. It won't rotate if the default delimiter is found in the array.

#include <Array.au3>

Local $aArray[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
_ArrayDisplay($aArray, "BEFORE rotation")
If _ArrayRotate($aArray, 4) Then
    _ArrayDisplay($aArray, "AFTER rotation")
Else
    MsgBox(Default, Default, "Array did not rotate!")
EndIf

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

    If StringInStr(_ArrayToString($aArray, ""), "|") Then Return False ; default delimiter found in array

    Local $sArray = _ArrayToString($aArray)
    Local $iPos = StringInStr($sArray, "|", $STR_NOCASESENSE, $iMakeFirst)
    Local $sFirst = StringLeft($sArray, $iPos - 1)
    Local $sLast = StringRight($sArray, StringLen($sArray) - $iPos)
    $aArray = _ArrayFromString($sLast & "|" & $sFirst)
    Return True

EndFunc   ;==>_ArrayRotate

 

Link to post
Share on other sites
Local $aArray[] = ["000", "100", "200", "300", "400", "500", "600", "700", "800", "900"]
_ArrayDisplay(__ArrayRotate($aArray, 4))

Func __ArrayRotate(ByRef $aArray, $iIndex, $sSeparator = '|')
    Return StringRegExp(StringRegExpReplace(_ArrayToString($aArray, $sSeparator), '(.*?)\'& $sSeparator  &'(?=' & $aArray[$iIndex] & ')(.*)', _
                                            '$2\' & $sSeparator & '$1'), '([^\' & $sSeparator & ']+)', 3)
EndFunc

 

Link to post
Share on other sites

Doubling the array...

#Include <Array.au3>

Local $aArray[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

_ArrayRotate($aArray, 4)

Func _ArrayRotate(ByRef $aArray, $iShift)
   Local $aArray2[] = $aArray
   _ArrayAdd($aArray2, $aArray)
   For $i = 0 To UBound($aArray) - 1
      $aArray[$i] = $aArray2[$i + $iShift]
   Next
EndFunc

_ArrayDisplay($aArray)

 

Some guy's script + some other guy's script = my script!

Link to post
Share on other sites

To complete the results:

@jchd Your ArrMove method averaged 24.3164 ms

@Werty Your method averaged 73.2607 ms - thanks for pulling me out of last place! 😁

The other methods that convert the array to a delimited string I'm going to rule out (for me) because of the danger of scrambled results due to a delimiter character possibly being within the array data. Those methods have certainly presented some interesting approaches, but I don't think they're 100% reliable.

So in order of speed, with the fastest at the top, we've ended up with:

pixelsearch

jchd

Danp2

TimRude

Werty

Also, it may be worth noting for posterity's sake that while I asked about doing this for a 1D array, the methods used by pixelsearch and myself will also handle 2D arrays, whereas the others work on 1D arrays only.

Thanks everyone for your examples!

Edited by TimRude
Link to post
Share on other sites

Incredible that we got so many different solutions in this thread, well done guys !

It makes me realize that my way of thinking is a bit odd... for example when OP got nearly the same question in the other thread (where I scripted _ArrayRowMove), I didn't script it for him only, having in mind that maybe the array could be 1D or 2D, maybe the block of rows to move should be placed at bottom of the array and not always on top etc...

Well, I guess we all got a different way of thinking, it's a bit too late to change it :bye:

Edit: didn't realize TimRude just answered before me !

Edited by pixelsearch
Link to post
Share on other sites
  • TimRude changed the title to Rotating values within an array [SOLVED]
10 hours ago, TimRude said:

handle 2D arrays

Instead of moving large data chunks around, you could just operate on a 1D numeric index array with which to access your 2D data.

EDIT: in this case, E4A would do this in a fraction of the time (about 3 ms on my machines):

Spoiler

#include "Eigen4AutoIt.au3"

_Eigen_StartUp()

$rows=2891
$newtop=int($rows/2)

$matData = _Eigen_CreateMatrix_LinSpaced_Rowwise ( $rows, 1, 0, $rows-1 )
;_MatrixDisplay ( $matA, "matrix A" )

$timer=TimerInit()
$matA = _Eigen_Remap_MatrixRows ( $matData, $newtop, $rows-$newtop )
$matB = _Eigen_Remap_MatrixRows ( $matData, 0, $newtop )
$matR = _Eigen_CreateMatrix_FromABrows ( $matA, $matB )
$diff=TimerDiff($timer)
_MatrixDisplay ( $matR, $diff & " ms")

_Eigen_CleanUp()

; NB _Eigen_Remap_MatrixRows is unfortunately absent from current release, but looks like this (copy & paste it into Eigen4Autoit.au3):

Func _Eigen_Remap_MatrixRows($matA, $firstrow, $rows, $E4Asln = @ScriptLineNumber)
    ; returns new index to $matrixList (matID)

    Local $procname = "_Eigen_Remap_MatrixRows"
    _Eigen_Callstack_Push($procname, $E4Asln)

    If Not IsInt($firstrow) Or $firstrow < 0 Then Return SetError(_Eigen_Callstack_ErrorHandler(-2, "invalid matrix row coordinate (firstrow = " & $firstrow & ")", $procname, Default, $E4Asln), 0, False)
    If Not IsInt($rows) Or $rows <= 0 Then Return SetError(_Eigen_Callstack_ErrorHandler(-2, "invalid matrix rows dimension (rows = " & $rows & ")", $procname, Default, $E4Asln), 0, False)

    Local $matA_ptr = _Eigen_GetPtr($matA, "A", Default, Default, $E4Asln)
    If @error Or $matA_ptr = 0 Then Return SetError(_Eigen_Callstack_ErrorHandler(-3, "unable to retrieve valid matrix pointer", $procname, Default, $E4Asln), 0, False)
    If _Eigen_Check_Row($matA, $firstrow, $E4Asln) = False Then Return SetError(_Eigen_Callstack_ErrorHandler(-2, "invalid matrix row coordinate (firstrow = " & $firstrow & ")", $procname, Default, $E4Asln), 0, False)
    If _Eigen_IsVector($matA, $E4Asln) = False Then Return SetError(_Eigen_Callstack_ErrorHandler(-2, "source matrix should be a vector", $procname, Default, $E4Asln), 0, False)

    Local $offset = 0
    If $firstrow > 0 Then
        $offset = $firstrow * _Eigen_MatrixTypeID_ToBytes($matrixList[$matA][3])
        If @error Then Return SetError(_Eigen_Callstack_ErrorHandler(-2, "invalid matrix type definition", $procname, Default, $E4Asln), 0, False)
    EndIf

    ; update MatrixList entry
    Local $newmatID = _Eigen_GetNewMatrixID($E4Asln)

    $matrixList[$newmatID][1] = $rows
    $matrixList[$newmatID][2] = 1
    $matrixList[$newmatID][3] = $matrixList[$matA][3]
    $matrixList[$newmatID][4] = Ptr($matA_ptr + $offset)
    $matrixList[$newmatID][5] = StringTrimLeft($procname, 7) & ":" & $matA
    $matrixList[$newmatID][6] = False
    $matrixList[$newmatID][7] = True
    $matrixList[0][0] = $newmatID

    ; flag source matrix as remapped
    $matrixList[$matA][6] = True

    Switch @AutoItX64
        Case False
            $matrixList[$newmatID][0] = DllStructCreate(_Eigen_MatrixTypeID_ToTypeLabel($matrixList[$matA][3]) & "[" & $rows * (1 + _Eigen_IsComplex($matA, $E4Asln)) & "]", Ptr($matA_ptr + $offset))
    EndSwitch
    If $EIGEN_VERBOSE = True Then ConsoleWrite("E4A Remapping (" & $matrixList[$matA][1] & "," & $rows & ") from row " & $firstrow & " of existing matrix ID " & $matA & " with new matrix ID: " & $matA & @CRLF)

    $EIGEN_ML_HASCHANGED = True
    If $EIGEN_ML_HASCHANGED_UDF <> "" Then Call($EIGEN_ML_HASCHANGED_UDF)

    _Eigen_Callstack_Pop($procname)
    Return $newmatID
EndFunc   ;==>_Eigen_Remap_MatrixRows

 

 

Edited by RTFC
shameless bragging
Link to post
Share on other sites
11 hours ago, RTFC said:

Instead of moving large data chunks around, you could just operate on a 1D numeric index array with which to access your 2D data

I'm not actually working with a 2D array. But I have ended up creating a second array that holds just the index numbers of the first array that holds the actual data. Then I do my rotating on the index-array.

As such, pretty much any of the suggested methods then become fast enough.

Edited by TimRude
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ioa747
      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
    • By Mannyfresh31
      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  
    • By ahha
      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.
    • By nooneclose
      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  
    • By VinMe
      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)
×
×
  • Create New...