Hi everybody .....

i write this code to select rundom from list box(1)[have decimal number ] and but in the listbox(2) in list box 2 select the max value and but in the listbox(3)
((for examble i but 4 number in listbox(1)the function find 4 random number and find th max and do the function 4 times ))

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Randomize()
Dim Smax As String
For h = 0 To ListBox1.Items.Count - 1
For i = 0 To ListBox1.Items.Count - 1
Dim R As Long
R = ListBox1.Items.Count - 1
ListBox1.SelectedIndex = Rnd() * R
ListBox2.Items.Add(ListBox1.SelectedItem.ToString)

Dim n As Integer
For n = 0 To Me.ListBox2.Items.Count - 1
If Me.ListBox2.Items(n) > Smax Then

Smax = Me.ListBox2.Items(n)
Else

Smax = Smax
End If

Next

Next
Me.ListBox3.Items.Add(Smax)

Next

End Sub

Question :
i want to convert this code and put the result in arraylist rather than listbox
we should in the code no used the listbox !!!!!

how to do this?????????????

Change ListBoxN.Items to ArrayList

hi ddanbe...Thanks

i Know..... Change ListBoxN.Items to ArrayList

but how to do this in arraylist??

R = ListBox1.Items.Count - 1
ListBox1.SelectedIndex = Rnd() * R
ListBox2.Items.Add(ListBox1.SelectedItem.ToString)

how to make rundom select index in array ??????

If you help me, I appreciate you

Dim rnd As New Random()

R = ListBox1.Items.Count - 1 ---> R = ArraList1.Count
ListBox1.SelectedIndex = Rnd() * R ---> int SelectedIndex =rnd.Next(0,R)
ListBox2.Items.Add(ListBox1.SelectedItem.ToString) ---> ArrayList2.Add(ArrayList1.Item(SelectedIndex)

Maby some type errors here but I hope you get the general idea. Succes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.