Modify

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#2565 closed Bug (Fixed)

_ArrayCombinations - UDF ? DOC example ? - never ending loop

Reported by: mlipok Owned by:
Milestone: Component: Standard UDFs
Version: 3.3.9.25 Severity: None
Keywords: Cc:

Description

EXAMPLE (from doc): now is:

; Declare a 1-dimensional array, and create an array showing the Possible Combinations

#include <Array.au3>

Local $aArray[5] = [1, 2, 3, 4, 5]

For $i = 1 To UBound($aArray)
    Local $aArrayCombo = _ArrayCombinations($aArray, $i, ",")
    _ArrayDisplay($aArrayCombo, "iSet = " & $i)
Next

I modyfi by adding ConsoleWrite:

; Declare a 1-dimensional array, and create an array showing the Possible Combinations

#include <Array.au3>

Local $aArray[5] = [1, 2, 3, 4, 5]

For $i = 1 To UBound($aArray)
	ConsoleWrite('$i = ' & $i & @CRLF)
	Local $aArrayCombo = _ArrayCombinations($aArray, $i, ",")
	_ArrayDisplay($aArrayCombo, "iSet = " & $i)
Next

NEGATIVE RESULTS:

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /beta /ErrorStdOut /in "C:\Program Files (x86)\AutoIt3\Beta\Examples\Helpfile\_ArrayCombinations2.au3" /UserParams    
+>23:10:02 Starting AutoIt3Wrapper v.2.1.3.2 SciTE v.3.3.7.0 ;  Keyboard:00000415  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64    Environment(Language:0415  Keyboard:00000415  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64)
>Running AU3Check (3.3.9.25)  from:C:\Program Files (x86)\AutoIt3\Beta
+>23:10:02 AU3Check ended.rc:0
>Running:(3.3.9.25):C:\Program Files (x86)\AutoIt3\Beta\autoit3.exe "C:\Program Files (x86)\AutoIt3\Beta\Examples\Helpfile\_ArrayCombinations2.au3"    
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
$i = 1
$i = 1
$i = 1
$i = 1
$i = 1
$i = 1
$i = 1
$i = 1
$i = 1
$i = 1
$i = 1
$i = 1
$i = 1
$i = 1
$i = 1
$i = 1
$i = 1
$i = 1
$i = 1
$i = 1
....
...
..
.

next modyfication (added comment for _ArrayDisplay):

; Declare a 1-dimensional array, and create an array showing the Possible Combinations

#include <Array.au3>

Local $aArray[5] = [1, 2, 3, 4, 5]

For $i = 1 To UBound($aArray)
	ConsoleWrite('$i = ' & $i & @CRLF)
	Local $aArrayCombo = _ArrayCombinations($aArray, $i, ",")
;~ 	_ArrayDisplay($aArrayCombo, "iSet = " & $i)
Next

POSITVE RESULT:

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /beta /ErrorStdOut /in "C:\Program Files (x86)\AutoIt3\Beta\Examples\Helpfile\_ArrayCombinations2.au3" /UserParams    
+>23:11:57 Starting AutoIt3Wrapper v.2.1.3.2 SciTE v.3.3.7.0 ;  Keyboard:00000415  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64    Environment(Language:0415  Keyboard:00000415  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64)
>Running AU3Check (3.3.9.25)  from:C:\Program Files (x86)\AutoIt3\Beta
+>23:11:57 AU3Check ended.rc:0
>Running:(3.3.9.25):C:\Program Files (x86)\AutoIt3\Beta\autoit3.exe "C:\Program Files (x86)\AutoIt3\Beta\Examples\Helpfile\_ArrayCombinations2.au3"    
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
$i = 1
$i = 2
$i = 3
$i = 4
$i = 5
+>23:11:57 AutoIt3.exe ended.rc:0
>Exit code: 0    Time: 0.895


btw:
I notice Local declaration inside loop ( Local $aArrayCombo )
but this is not connected with the bug described above

Attachments (0)

Change History (9)

comment:1 Changed 6 years ago by BrewManNH

The bug isn't with _ArrayCombinations, it only appears when used with _ArrayDisplay. Something in _ArrayDisplay is resetting the $i variable.

#include <Array.au3>

Global $aArray[5] = [1, 2, 3, 4, 5]
Global $aArrayCombo
For $i = 1 To UBound($aArray)
	ConsoleWrite('Before _ArrayCombinations, $i = ' & $i & @CRLF)
	$aArrayCombo = _ArrayCombinations($aArray, $i, ",")
	ConsoleWrite('After _ArrayCombinations and before _ArrayDisplay, $i = ' & $i & @CRLF)
	_ArrayDisplay($aArrayCombo);, "iSet = " & $i)
	ConsoleWrite('After _ArrayDisplay, $i = ' & $i & @CRLF)
Next

This doesn't happen in 3.3.9.24.

comment:2 Changed 6 years ago by BrewManNH

BTW, you'll notice that I'm narrowing the problem down to just the _ArrayDisplay without a title, just in case something to do with setting the title messed things up.

comment:3 Changed 6 years ago by BrewManNH

Ok, just tested this again, same code except I used a variable name of $zzzzzzzzz instead of $i. The problem doesn't happen doing it with $zzzzzzzzz instead of $i. So, something in _ArrayDisplay is definitely resetting $i to zero.

comment:4 Changed 6 years ago by mlipok

So in general:
error actually is
but for a new function: _ArrayDisplay

which I pointed out in the opening post TICKET
I mean: "next modyfication (added comment for _ArrayDisplay)"

comment:5 Changed 6 years ago by Melba23

Found the problem in _ArrayDisplay.

There is a line which is intended to set a default value to a variable $i if it is not being set in a loop:

; Create custom header with available items
If $asHeader[0] Then
	; Set as many as available
	For $i = $iSubItem_Start To $iSubItem_End
		; Check custom header available
		If $iIndex >= UBound($asHeader) Then ExitLoop
		$sHeader &= $sAD_Separator & $asHeader[$i]
	Next
Else
	; Set default start
	$i = $iSubItem_Start ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
EndIf

That default line was in fact changing the Global variable $i and not the forced Local loop counter created in other circumstances. A nice little "gotcha" which was not picked up by any of the checking tools (I presume because there was already a Local $i declared) and which I will definitely remember for the future.

Fixed in the next Beta by using a Local variable with a different name for both the loop and default variable. And before you ask, I have checked the rest of the function and all other instances of an $i variable are forced Local by a preceding For.

M23

comment:6 Changed 6 years ago by Melba23

  • Resolution set to Fixed
  • Status changed from new to closed

comment:7 Changed 6 years ago by guinness

There is no linked revision number to the bug fix.

comment:8 Changed 6 years ago by guinness

There is no linked revision number to the bug fix.

comment:9 Changed 6 years ago by Melba23

Other parts of the function were also modifed - not just this bug fix - so the commit was entered as "Changed" not "Fixed". Would you like me to make a further commit to link to this ticket?

M23

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.