Copy this code into a notepad and save it as .vbs file. Provide input so do ku puzzle in an excel sheel as shown in the screenshot to the program.
When iput file is read, give its path to the program and also the output path where you want to place the output.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Version:0.9 StartHTML:00000107 EndHTML:00038478 EndFragment:00038438 EndFragment:00000000
When iput file is read, give its path to the program and also the output path where you want to place the output.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Version:0.9 StartHTML:00000107 EndHTML:00038478 EndFragment:00038438 EndFragment:00000000
sStartTime = Now
Set oXLObj = CreateObject("Excel.Application")
oXLObj.Visible = True
Set oXLWB = oXLObj.Workbooks.Open ("D:\personal\Sudoku\PuzzleFile.xlsx")
Set oXL = oXLWB.Worksheets("Sudoku")
sNumString = "123456789"
For iRow = 1 To 9
For iCoulmn = 1 To 9
If Len(Trim(oXL.Cells(iRow,iCoulmn))) = 0 Then
sFillerString = sNumString
For iSubRow = 1 To 9
If Len(oXL.Cells(iSubRow,iCoulmn)) = 1 Then
sFillerString = Replace(sFillerString, oXL.Cells(iSubRow,iCoulmn),"")
End If
Next
For iSubCoulmn = 1 To 9
If Len(oXL.Cells(iRow,iSubCoulmn)) = 1 then
sFillerString = Replace(sFillerString, oXL.Cells(iRow,iSubCoulmn),"")
End If
Next
oXL.Cells(iRow,iCoulmn) = sFillerString
End If
Next
Next
Function FillCells(iFRomRow, iToRow, iFromColumn, iToCoulmn)
For iTempRow = iFRomRow To iToRow
For iTempCoulmn = iFromColumn To iToCoulmn
If Len(oXL.Cells(iTempRow, iTempCoulmn)) > 1 Then
For iTemp_Row = iFRomRow To iToRow
For iTemp_Coulmn = iFromColumn To iToCoulmn
If Len(oXL.Cells(iTemp_Row, iTemp_Coulmn)) = 1 And iTemp_Row <> iTempRow And iTempCoulmn <> iTemp_Coulmn Then
oXL.Cells(iTempRow, iTempCoulmn) = Replace(oXL.Cells(iTempRow, iTempCoulmn),oXL.Cells(iTemp_Row, iTemp_Coulmn),"")
End If
Next
Next
End If
Next
Next
End Function
Function PuzzleStatus ()
ExitFlag = "False"
For iRow = 1 To 9
For iCoulmn = 1 To 9
If Len(Trim(oXL.Cells(iRow,iCoulmn))) <> 1 Then
ExitFlag = "True"
Exit For
End If
Next
If ExitFlag = "True" Then
Exit For
End If
Next
If ExitFlag = "True" Then
PuzzleStatus = "NotSolved"
ElseIf ExitFlag = "False" Then
PuzzleStatus = "Solved"
End If
End Function
FillCells 1, 3, 1, 3
FillCells 1, 3, 4, 6
FillCells 1, 3, 7, 9
FillCells 4, 6, 1, 3
FillCells 4, 6, 4, 6
FillCells 4, 6, 7, 9
FillCells 7, 9, 1, 3
FillCells 7, 9, 4, 6
FillCells 7, 9, 7, 9
iLoopCount = 1
Do While PuzzleStatus = "NotSolved"
For iRow = 1 To 9
For iCoulmn = 1 To 9
If Len(Trim(oXL.Cells(iRow,iCoulmn))) > 1 Then
sFillerString = oXL.Cells(iRow,iCoulmn)
For iSubRow = 1 To 9
If Len(oXL.Cells(iSubRow,iCoulmn)) = 1 Then
sFillerString = Replace(sFillerString, oXL.Cells(iSubRow,iCoulmn),"")
End If
Next
For iSubCoulmn = 1 To 9
If Len(oXL.Cells(iRow,iSubCoulmn)) = 1 then
sFillerString = Replace(sFillerString, oXL.Cells(iRow,iSubCoulmn),"")
End If
Next
oXL.Cells(iRow,iCoulmn) = sFillerString
End If
Next
Next
FillCells 1, 3, 1, 3
FillCells 1, 3, 4, 6
FillCells 1, 3, 7, 9
FillCells 4, 6, 1, 3
FillCells 4, 6, 4, 6
FillCells 4, 6, 7, 9
FillCells 7, 9, 1, 3
FillCells 7, 9, 4, 6
FillCells 7, 9, 7, 9
iLoopCount = 1 + iLoopCount
If iLoopCount = 100 Then
Exit Do
End If
Loop
sEndTime = Now
MsgBox PuzzleStatus & vbNewLine & sStartTime & vbNewLine & sEndTime
oXLWB.Save
oXLWB.Close
oXLObj.Quit
Set oXLObj = Nothing

No comments:
Post a Comment