Question[Help]random selections ComboBox

Posts 1–5 of 5 · Page 1 of 1
[Help]random selections ComboBox
I mean make a button and then it will randomly select and option for you.
Quote Originally Posted by ppl2pass View Post
I mean make a button and then it will randomly select and option for you.
Code:
Dim i as new random

Dim x as integer= i.next (0,combobox1.items.count-1)

Combobox1.selectedindex=x
ok thanks. how do you make it select random options but not select a few of the options.

ex.

comboBox1 List:
apples
oranges
pears


random:
selects any option but the oranges.
so only select from pears and apples.
You could put options in an array if you wanted and have the button select an option from the array.
Try this

[php]

Private Sub RandomCombo()

Dim I As New Random
Dim X As Integer = I.Next(0, ComboBox1.Items.Count - 1)

ComboBox1.SelectedIndex = X

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
RandomCombo()

End Sub

Private Sub ComboBox1_SelectedItemChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedItem = "APPLES" Then
RandomCombo()
End If
End Sub
[/php]

Essentially create a sub to call random index,
Button press goes to sub

on item change check if it is "Apples" , if so Re roll

note : have not tested, using above theory and basic principles, if not, concept may need modification

Posts 1–5 of 5 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us