Ver Mensaje Individual
  #4 (permalink)  
Antiguo 07/06/2009, 02:53
Avellaneda
Colaborador
 
Fecha de Ingreso: enero-2008
Ubicación: Unas veces aquí, otras veces allí
Mensajes: 1.482
Antigüedad: 16 años, 3 meses
Puntos: 37
Respuesta: numeros aleatorios no repetidos

Cita:
Iniciado por coor Ver Mensaje
pero lo necesito el codigo en visual basic
Primero cargas los aleatorios (descartando los repetidos) en un array y después los vuelcas a las etiquetas:

Código vb6.0:
Ver original
  1. Private Sub cmdjugar_Click()
  2. Dim MiVector(4) As Integer, iCont As Integer, j As Integer, x As Integer
  3. Dim oControl As Label
  4.  
  5. ' inicializamos el generador de aleatorios
  6. Randomize
  7. For iCont = 0 To 4
  8. inicio:
  9.     ' generamos un aleatorio entre el 1 y el 100
  10.     x = Int(100 * Rnd)
  11.     For j = 0 To iCont
  12.         ' si el número ya existe en el array, lo descartamos
  13.         If x = MiVector(j) Then GoTo inicio
  14.     Next j
  15.     ' no existe, lo añadimos a la matriz
  16.     MiVector(iCont) = x
  17. Next iCont
  18. ' cargamos las etiquetas
  19. Label1.Caption = MiVector(0)
  20. Label2.Caption = MiVector(1)
  21. Label3.Caption = MiVector(2)
  22. Label4.Caption = MiVector(3)
  23. Label5.Caption = mivector4
  24. End Sub