Visual Basic - COMO HACER UN FUNCTION EN ESTE SUDOKU

Life is soft - evento anual de software empresarial
 
Vista:

COMO HACER UN FUNCTION EN ESTE SUDOKU

Publicado por inter (7 intervenciones) el 19/02/2007 17:08:25
Hola ha todos tengo una duda que no se como arreglarlo y es que tengo dos botones uno para crear y el otro para solucionar y los quiero usar para que cuando pulse el boton crear te salgan a las 81 casillas los sudokus completados sin que tenga que utlizar el boton solucionar alguno me puede ayudar,me han dicho que con un function era suficiente pero me da error cada vez alguien me lo puede esplicar como se hace?

este es mi codigo

Const Gris As Long = &HC0C0C0
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
End Sub
-----------------------------------------------------------------------------
Private Function CreateSudokuGrid() As Boolean
Dim 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
Sudoku(i).Caption = ""
Sudoku(i).BackColor = Gris
Sudoku(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
Sudoku(i).Caption = CStr(j)
Sudoku(i).BackColor = Gris
End If
Next i
lblConfiguring.Visible = False
For i = 1 To 81
SudokuSolution(i) = Sudoku(i).Caption
numRand = Rnd(CInt(spnDifficulty.Text) + 1) + 1
If numRand > 1 Then
Sudoku(i).Caption = ""
Sudoku(i).BackColor = Gris
Sudoku(i).Enabled = True
Else
Sudoku(i).Enabled = False
End If
Sudoku(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 Sudoku(k).Caption = 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 Sudoku(k).Caption = 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 * 3) + Int((j - 1) / 3)) * 9) + (col * 3) + ((j - 1) Mod 3) + 1
If Sudoku(k).Caption = numStr Then
numOK = False
Exit For
End If
Next j
End If
ValidVals(i) = numOK
If numOK Then
retVal = retVal + 1
End If
Next i
GetValidVals = retVal
End Function
----------------------------------------------------------------------------
Private Sub cmdSolucion_Click()
Dim i As Integer

If SolutionShown Then
For i = 1 To 81
Sudoku(i).Caption = SudokuTemp(i)
Next i
cmdSolucion.Caption = "Show Solution"
Else
For i = 1 To 81
SudokuTemp(i) = Sudoku(i).Caption
Sudoku(i).Caption = SudokuSolution(i)
Next i
cmdSolucion.Caption = "Hide Solution"
End If
SolutionShown = Not SolutionShown
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:COMO HACER UN FUNCTION EN ESTE SUDOKU

Publicado por quique (1 intervención) el 19/02/2007 18:55:42
¡argh!, que flojera de leer todo eso
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:COMO HACER UN FUNCTION EN ESTE SUDOKU

Publicado por carlos (1 intervención) el 19/02/2007 19:54:55
pues no lo leas
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:COMO HACER UN FUNCTION EN ESTE SUDOKU

Publicado por martin (7 intervenciones) el 20/02/2007 06:30:58
solo me basta que me digais como se aria el function como lo puedo hacer?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar