Mikel01 de Septiembre del 2002
PreguntaHola quiero generar una lista de 16 elementos con numeros aleatorios de 1 al 8 y cada numero se tiene repetir solo una vez. Este es el codigo que he escrito y que no funciona. Si alguien me pudiera ayudar se lo agradeceria mucho.Private Sub Form_Load()
X = 0
Randomize
While lstOrden.ListCount < 16
MiValor = Int((8 * Rnd) + 1)
For i = 0 To lstOrden.ListCount - 1
If lstOrden.List(i) = MiValor Then
X = 1 + X
Else: X = 0
If X = 2 Then
i = lstOrden.ListCount - 1
End If
End If
Next i
If X = 0 Then
lstOrden.AddItem MiValor
End If
If X = 1 Then
lstOrden.AddItem MiValor
End If
Wend
X = 0
Randomize
While lstOrden.ListCount < 16
MiValor = Int((8 * Rnd) + 1)
For i = 0 To lstOrden.ListCount - 1
If lstOrden.List(i) = MiValor Then
X = 1 + X
Else: X = 0
If X = 2 Then
i = lstOrden.ListCount - 1
End If
End If
Next i
If X = 0 Then
lstOrden.AddItem MiValor
End If
If X = 1 Then
lstOrden.AddItem MiValor
End If
Wend
