Hola. Nesecito de su ayuda gente.
Por un lado tengo una lista de 10 nombres de varones. Guardados en un ListBox o un ComboBox, me da igual. Y un CommandButton1, al lado.
Y por otro lado una lista de 10 nombres de mujeres. Y un CommandButton2, al lado.
Lo q quiero es q al tildar el boton1, me elija aleatoriamente 1 nombre de la lista de varones y me lo muestre en un Label o un TextBox y al presionar el Boton 2, me haga lo mismo pero con los nombres de mujeres.
Muchas Gracias.
Saludos!
Mira haslo asi:
Option Explicit
Private Sub Command1_Click()
Label3.Caption = List1.List(Int(Rnd * List1.ListCount))
End Sub
Private Sub Command2_Click()
Label4.Caption = List2.List(Int(Rnd * List2.ListCount))
End Sub
Private Sub Form_Load()
With List1
.AddItem "Juan"
.AddItem "Pedro"
.AddItem "Jose"
.AddItem "Carlos"
.AddItem "Cabron"
End With
With List2
.AddItem "Juana"
.AddItem "Petra"
.AddItem "Josefa"
.AddItem "Carla"
.AddItem "p**a"
End With
End Sub
el codigo esta bien... pero si lo dejas asi, siemrpe el primer varon sera Carlos (en mi computadora, en la tuya quizas sea otro...
lo mejor seria asi..
Option Explicit
Private Sub Command1_Click()
Randomize
Label3.Caption = List1.List(Int(Rnd * List1.ListCount))
End Sub
Private Sub Command2_Click()
Randomize
Label4.Caption = List2.List(Int(Rnd * List2.ListCount))
End Sub
Private Sub Form_Load()
With List1
.AddItem "Juan"
.AddItem "Pedro"
.AddItem "Jose"
.AddItem "Carlos"
.AddItem "Cabron"
End With
With List2
.AddItem "Juana"
.AddItem "Petra"
.AddItem "Josefa"
.AddItem "Carla"
.AddItem "p**a"
End With
End Sub
llamar a Randomize antes del Rnd :P
probalo y decime :P
SALUDOS
Si me habia dado q cuenta q siempre tiraba el mismo orden.
Con el Randomize se solucionó.
Muchas Gracias, era lo q nesecitaba.
Saludos