I played a bit more with the code. Now it supports to free a number. Unfortunately the autoupdate doesn't always work correctly. I will not have time to fix this, but maybe someone else has the time to continue.
This are only 190 lines.
Code:
Index = ABCDEFGHI
Loop, Parse, Index
{
Position = xm Section
Row = %A_LoopField%
Loop, 9 {
A%Row%%A_Index% = 123456789
Gui, Add, DropDownList, %Position% w35 number Sort v%Row%%A_Index% gDDLCLICK, 1|2|3|4|5|6|7|8|9
Position = ys
}
}
Gui, Add, Button,xm gBtnReset, Reset
Gui, Show,, SuDoKu Helper
Return
GuiEscape:
GuiClose:
ExitApp
BtnReset:
Reload
return
DDLCLICK:
GuiCntrl = %A_GuiControl%
AutoUpdate:
SetBatchLines, -1
AutoUpdate =
StringLeft, Row, GuiCntrl, 1
StringRight, Column, GuiCntrl, 1
OldValue := %GuiCntrl%
Gui, Submit, NoHide
Selection := %GuiCntrl%
;free the previous value if there was one
If OldValue is not space
GoSub, FreeValue
GoSub, EliminateValue
;add and select selected value again
If Selection is not space
{
GuiControl, , %GuiCntrl%, %Selection%||
A%GuiCntrl% := A%GuiCntrl% . Selection
}
Else
GuiControl, Choose, %GuiCntrl%,1
;Loop through AutoUpdates
StringReplace, AutoUpdate, AutoUpdate, %GuiCntrl%,,All
Loop,Parse, AutoUpdate, |
{
If A_LoopField is not space
{
GuiCntrl = %A_LoopField%
GoSub, AutoUpdate
}
}
Return
LoopFieldsToEliminate:
Loop, parse, LoopOverRows
{
CurrentRow := A_LoopField
Loop, parse, LoopOverColumns
{
z = %CurrentRow%%A_LoopField%
x := A%z%
y := %z%
StringReplace, x, x, %Selection%
A%z% = %x%
varx =
Loop, Parse, x
varx = %varx%%A_LoopField%|
StringTrimRight, varx, varx, 1
GuiControl, , %z%, ||%varx%
If y is not space
{
If x is not space
GuiControl, ChooseString, %z%, %y%
}
Else If varx is integer
{
GuiControl, ChooseString, %z%, %varx%
AutoUpdate = %AutoUpdate%|%z%
}
}
}
return
EliminateValue:
;clean horizontal
LoopOverRows = %Row%
LoopOverColumns = 123456789
GoSub, LoopFieldsToEliminate
;clean vertical
LoopOverRows = ABCDEFGHI
LoopOverColumns = %Column%
GoSub, LoopFieldsToEliminate
;clean its own block
GoSub, GetRemainingBlockFields
GoSub, LoopFieldsToEliminate
Return
GetRemainingBlockFields:
RowBlocks = A,B,C|D,E,F|G,H,I
Loop, Parse, RowBlocks, |
If Row in %A_LoopField%
{
StringReplace, LoopOverRows, A_LoopField, %Row%
StringReplace, LoopOverRows, LoopOverRows, `,,,All
Break
}
ColumnBlocks = 1,2,3|4,5,6|7,8,9
Loop, Parse, ColumnBlocks, |
If Column in %A_LoopField%
{
StringReplace, LoopOverColumns, A_LoopField, %Column%
StringReplace, LoopOverColumns, LoopOverColumns, `,,,All
Break
}
Return
FreeValue:
;empty valuestrings
Loop, 9 {
RowValues%A_Index% =
ColumnValues%A_Index% =
BlockValues%A_Index% =
}
;get valuestrings by rows, columns and blocks
LoopOverRows = ABCDEFGHI
LoopOverColumns = 123456789
Loop, parse, LoopOverRows
{
CurrentRow := A_loopfield
RowID := A_Index
BlockRowID := Floor((RowID - 1) / 3)
Loop, parse, LoopOverColumns
{
y := %CurrentRow%%A_loopfield%
RowValues%RowID% := RowValues%RowID% . y
ColumnValues%A_loopfield% := ColumnValues%A_loopfield% . y
BlockID := (Floor((A_loopfield -1)/ 3) + 1) + 3 * BlockRowID
BlockValues%BlockID% := BlockValues%BlockID% . y
}
}
;add value horizontal if not in column or row or block string
LoopOverRows = %Row%
LoopOverColumns = 123456789
StringReplace, LoopOverColumns, LoopOverColumns, %Column%
GoSub, LoopFieldsToFree
;add value vertical if not in column or row or block string
LoopOverRows = ABCDEFGHI
StringReplace, LoopOverRows, LoopOverRows, %Row%
LoopOverColumns = %Column%
GoSub, LoopFieldsToFree
;add value to its own block if not in column or row string
GoSub, GetRemainingBlockFields
GoSub, LoopFieldsToFree
Return
LoopFieldsToFree:
Loop, parse, LoopOverRows
{
CurrentRow := A_LoopField
RowID := Asc(CurrentRow) - 64
If (InStr(OldValue, "a" . RowValues%RowID%) = 0){
RowID := Floor((RowID - 1) / 3)
Loop, parse, LoopOverColumns
If (InStr(OldValue, "a" . ColumnValues%A_LoopField%) = 0){
BlockID := (Floor((A_LoopField -1)/ 3) + 1) + 3 * RowID
If (InStr(OldValue, "a" . BlockValues%BlockID%) = 0){
z = %CurrentRow%%A_LoopField%
A%z% := A%z% . OldValue
GuiControl, , %z%, %OldValue%
}
}
}
}
Return