Visual Basic - ALGUIEN SABE COMO QUITAR LOS DOS 10 QUE ME SALEN?

Life is soft - evento anual de software empresarial
 
Vista:

ALGUIEN SABE COMO QUITAR LOS DOS 10 QUE ME SALEN?

Publicado por INTER (7 intervenciones) el 12/03/2007 16:53:55
Pues tengo una duda mañana tengo que entregar sin falta el sudoku y el problema es que cuando pulso el boton crear siempre me sale dos 10 aleatorio pero solo 2 y no se que hacer como quitarlos? alguien tiene un poquito de tiempo para ayudarme?

aqui teneis el codigo:
--------------------------------------------------------------------------
Private Sub cmdGenerar_Click()

CreateSudokuGrid

Dim i As Integer

For i = 1 To 81

Text1(i).Enabled = True
Text1(i).ForeColor = vbBlack
Text1(i).Enabled = False

Next i

End Sub
---------------------------------------------------------------------
Private Sub CreateSudokuGrid()

Dim b, i, j, k As Integer
Dim numRand As Integer
Dim ValIsOK(0 To 9) As Boolean
Dim valsOK As Integer

Do

For i = 1 To 81
Text1(i).Text = ""
Next i

For i = 1 To 81
If GetValidVals(i, ValIsOK()) = True Then
Randomize

Do
numRand = Int(10 * Rnd)
If ValIsOK(numRand) = True Then Exit Do
Loop

Text1(i) = numRand

Else

Text1(i) = "10"
End If
Next i
If isValid() Then Exit Do
Loop

For i = 1 To 81
Text1(i).Enabled = True
numRand = Rnd(CInt(3) + 1) + 1
If numRand > 1 Then

Text1(i).BackColor = Gris
Text1(i).ForeColor = vbBlack
Text1(i).Enabled = False
Else

Text1(i).BackColor = Blanco
Text1(i).ForeColor = Blanco

End If

Me.Refresh

Next i

End Sub
Private Function isValid()

Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim s(0 To 10) As Boolean

For i = 1 To 9
For j = 0 To 10: s(j) = False: Next j
For j = 1 To 9

k = (i - 1) * 9 + j
If s(Val(Me.Text1(k).Text)) = True Then
isValid = False: Exit Function
Else

s(Val(Me.Text1(k).Text)) = True

End If

Next j

Next i

For i = 1 To 9
For j = 0 To 10: s(j) = False: Next j
For j = 1 To 9

k = (j - 1) * 9 + i
If s(Val(Me.Text1(k).Text)) = True Then
isValid = False: Exit Function
Else

s(Val(Me.Text1(k).Text)) = True

End If

Next j

Next i

isValid = True

End Function
---------------------------------------------------------------------------------------
Private Function GetValidVals(ByVal Location As Integer, ByRef ValidVals() As Boolean) As Boolean

Dim i, j, k As Integer
Dim row, col As Integer
Dim numStr As String
Dim numOK As Boolean
Dim retVal As Boolean

For i = 1 To 9: ValidVals(i) = True: Next i

For i = 1 To 9

numStr = CStr(i)

For j = 1 To 9
k = (Int((Location - 1) / 9) * 9) + j
If Text1(k).Text = numStr Then ValidVals(i) = False
Next j

For j = 1 To 9
k = (((Location - 1) Mod 9) + 1) + ((j - 1) * 9)
If Text1(k).Text = numStr Then ValidVals(i) = False

Next j
Next i

retVal = False
For i = 1 To 9
retVal = IIf(ValidVals(i) = True, True, retVal)

Next i

GetValidVals = retVal

End Function
---------------------------------------------------------------------------------------
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:ALGUIEN SABE COMO QUITAR LOS DOS 10 QUE ME SALE

Publicado por inter (7 intervenciones) el 12/03/2007 17:40:24
el fallo podria venir de aqui??

Private Sub CreateSudokuGrid()

Dim b, i, j, k As Integer
Dim numRand As Integer
Dim ValIsOK(0 To 9) As Boolean
Dim valsOK As Integer

Do

For i = 1 To 81
Text1(i).Text = ""
Next i

For i = 1 To 81
If GetValidVals(i, ValIsOK()) = True Then
Randomize

Do
numRand = Int(10 * Rnd)
If ValIsOK(numRand) = True Then Exit Do
Loop

Text1(i) = numRand

Else

Text1(i) = "10"
End If
Next i
If isValid() Then Exit Do
Loop

For i = 1 To 81
Text1(i).Enabled = True
numRand = Rnd(CInt(3) + 1) + 1
If numRand > 1 Then

Text1(i).BackColor = Gris
Text1(i).ForeColor = vbBlack
Text1(i).Enabled = False
Else

Text1(i).BackColor = Blanco
Text1(i).ForeColor = Blanco

End If

Me.Refresh

Next i

End Sub
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