estoy apuntito de acabar el programa sudoku y solo me queda una dudilla he conseguido que la solucion se meta en el text, ya que cuando pulso el boton crear salgan completos pero cuando me salen completos me sale numeros 10 y yo me pregunto hay el numero 10 en el sudoku? no se esque me salen estos numeros he probado de todo poner
-1 ,+1 ,quitarlo etc pero sigue saliendo el 10 y porque los tres sudokus de arriba no cambian como los otros, pero la progunta que quiero es porque me sale los numeros 10?que tendria que cambiar?
--------------------------------------------
Const Gris As Long = &HFFFFFF
Private SolutionShown As Boolean
Private SudokuGrid(81) As Integer
Private SudokuTemp(81) As String
Private SudokuSolution(81) As String
----------------------------------------------------
Private Sub cmdGenerar_Click()
While Not CreateSudokuGrid()
Wend
lblDone.Visible = False
cmdSolucion.Enabled = True
cmdSolucion.Caption = "Show Solution"
SolutionShown = False
If SolutionShown Then
For i = 1 To 81
Text1(i).Text = SudokuTemp(i)
Next i
Else
For i = 1 To 81
SudokuTemp(i) = Text1(i).Text
Text1(i).Text = SudokuSolution(i)
Next
End If
End Sub
--------------------------------------------------
Private Function CreateSudokuGrid() As Boolean
Dim b, i, j, k As Integer
Dim numRand As Integer
Dim ValIsOK(9) As Boolean
Dim valsOK As Integer
valsOK = 0
lblConfiguring.Visible = True
For i = 1 To 81
Text1(i).Text = ""
Text1(i).BackColor = Gris
Text1(i).Visible = False
SudokuSolution(i) = ""
Next i
lblConfiguring.Visible = True
lblConfiguring.Refresh
For i = 1 To 81
If True Then
valsOK = GetValidVals(i, ValIsOK)
If valsOK <= 0 Then
CreateSudokuGrid = False
End If
numRand = Int(Rnd(valsOK)) + 1
k = 0
For j = 1 To 9
If ValIsOK(j) Then
k = k + 1
If k = numRand Then
Exit For
End If
End If
Next j
Text1(i).Text = CStr(j)
Text1(i).BackColor = Gris
End If
Next i
lblConfiguring.Visible = False
For i = 1 To 81
SudokuSolution(i) = Text1(i).Text
numRand = Rnd(CInt(3) + 1) + 1
If numRand > 1 Then
Text1(i).Text = ""
Text1(i).BackColor = Gris
Text1(i).Enabled = True
Else
Text1(i).Enabled = False
End If
Text1(i).Visible = True
Next i
CreateSudokuGrid = True
End Function
----------------------------------------------------
Private Function GetValidVals(ByVal Location As Integer, ByRef ValidVals() As Boolean) As Integer
Dim i, j, k As Integer
Dim row, col As Integer
Dim numStr As String
Dim numOK As Boolean
Dim retVal As Integer
retVal = 0
For i = 1 To 9
numOK = True
numStr = CStr(i)
For j = 1 To 9
k = (Int((Location - 1) / 9) * 9) + j
If Text1(k).Text = numStr Then
numOK = False
Exit For
End If
Next j
If numOK Then
For j = 1 To 9
k = (((Location - 1) Mod 9) + 1) + ((j - 1) * 9)
If Text1(k).Text = numStr Then
numOK = False
Exit For
End If
Next j
End If
If numOK Then
row = Int(Int((Location - 1) / 9) / 3)
col = Int(((Location - 1) Mod 9) / 3)
For j = 1 To 9
k = (((row * Rnd) + Int((j - 1) / 9)) * 9) + (col * 9) + ((j - 1) Mod 3) + 1
If Text1(k).Text = numStr Then
numOK = False
Exit For
End If
Next j
End If
ValidVals(i) = numOK
If numOK Then
retVal = retVal
End If
Next i
GetValidVals = retVal
End Function
--------------------------------------------------
Porque Me Salen El Numero 10 En El Sudoku???
Moderador: Moderadores
Hola de nuevo veo que no se ven las imagenes pero hoy he hablado con mi professor y me ha dicho que el posible fallo de que salgan los numero 10 es por el trozo que tengo abajo el sudoku esta compusto por 81 casillas textbox del 1 al 81 creando una matrix y un boton que genera el sudoku y el posible fallo dice mi profe que puede estar en este trozo y puede ser causa por el caracter " \ " este caracter me dice el profe que es para dividir y hay hay el posible fallo me podeis ayudar gracias:
Private Function GetValidVals(ByVal Location As Integer, ByRef ValidVals() As Boolean) As Integer
Dim i, j, k As Integer
Dim row, col As Integer
Dim numStr As String
Dim numOK As Boolean
Dim retVal As Integer
retVal = 0
For i = 1 To 9
numOK = True
numStr = CStr(i)
For j = 1 To 9
k = (Int((Location - 1) / 9) * 9) + j
If Text1(k).Text = numStr Then
numOK = False
Exit For
End If
Next j
If numOK Then
For j = 1 To 9
k = (((Location - 1) Mod 9) + 1) + ((j - 1) * 9)
If Text1(k).Text = numStr Then
numOK = False
Exit For
End If
Next j
End If
If numOK Then
row = Int(Int((Location - 1) / 9) / 3)
col = Int(((Location - 1) Mod 9) / 3)
For j = 1 To 9
k = (((row * Rnd) + Int((j - 1) / 9)) * 9) + (col * 9) + ((j - 1) Mod 3) + 1
If Text1(k).Text = numStr Then
numOK = False
Exit For
End If
Next j
End If
ValidVals(i) = numOK
If numOK Then
retVal = retVal
End If
Next i
GetValidVals = retVal
End Function
Private Function GetValidVals(ByVal Location As Integer, ByRef ValidVals() As Boolean) As Integer
Dim i, j, k As Integer
Dim row, col As Integer
Dim numStr As String
Dim numOK As Boolean
Dim retVal As Integer
retVal = 0
For i = 1 To 9
numOK = True
numStr = CStr(i)
For j = 1 To 9
k = (Int((Location - 1) / 9) * 9) + j
If Text1(k).Text = numStr Then
numOK = False
Exit For
End If
Next j
If numOK Then
For j = 1 To 9
k = (((Location - 1) Mod 9) + 1) + ((j - 1) * 9)
If Text1(k).Text = numStr Then
numOK = False
Exit For
End If
Next j
End If
If numOK Then
row = Int(Int((Location - 1) / 9) / 3)
col = Int(((Location - 1) Mod 9) / 3)
For j = 1 To 9
k = (((row * Rnd) + Int((j - 1) / 9)) * 9) + (col * 9) + ((j - 1) Mod 3) + 1
If Text1(k).Text = numStr Then
numOK = False
Exit For
End If
Next j
End If
ValidVals(i) = numOK
If numOK Then
retVal = retVal
End If
Next i
GetValidVals = retVal
End Function