Some kind of count function...trying to display the amount of numbers which are < .5.

kenascher

New member
Joined
Nov 14, 2006
Messages
3
Programming Experience
1-3
Some kind of count function...trying to display the amount of numbers which are < .5.

I have the following code so that when somebody hits the button, 25 random numbers are displayed, all between 0 and 1. I also have another button and 2 labels, where I want when somebody presses the other button, under 1 label to be the amount of numbers less than .5, and on the other label the amount of numbers greater than .5. How can this be done?

Public Class RdmNumGen

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


Label1.Text = Rnd()
Label2.Text = Rnd()
Label3.Text = Rnd()
Label4.Text = Rnd()
Label5.Text = Rnd()
Label6.Text = Rnd()
Label7.Text = Rnd()
Label8.Text = Rnd()
Label9.Text = Rnd()
Label10.Text = Rnd()
Label11.Text = Rnd()
Label12.Text = Rnd()
Label13.Text = Rnd()
Label14.Text = Rnd()
Label15.Text = Rnd()
Label16.Text = Rnd()
Label17.Text = Rnd()
Label18.Text = Rnd()
Label19.Text = Rnd()
Label20.Text = Rnd()
Label21.Text = Rnd()
Label22.Text = Rnd()
Label23.Text = Rnd()
Label24.Text = Rnd()
Label25.Text = Rnd()



End Sub




End Class
 
Hmm.. First of, why use that many variables? :S alot to keep track of..

Id do like this:
VB.NET:
Dim str(24) as integer

button1:

for i as integer = 0 to 24

str(i) = rnd()
textbox1.text = str(i) 'taking out the number you just placed in, to place it in the textbox or whatever you used to show the 25 numbers..

next

'making an array to store each rnd..

Button2:
For i as integer = 0 to 24

if str(i) < 0.5 then 
label1.text = Cint(label1.text) + 1 'convert string to number, just to be safe..

elseif str(i) > 0.5 then 
label2.text = Cint(label2.text) + 1
end if

next

Thats what you want?
 
That would work only...when that's run you get "Conversion from string "Label2" to type 'Integer' is not valid." What should I change?....Thanks!
 
VB.NET:
Dim over as integer
dim under as integer

if str(i) < 0.5 then 
under = under + 1
label1.text = under

elseif str(i) > 0.5 then 
over = over + 1
label2.text = over
end if
 
Back
Top