I have a problem displaying the correct random values extracted from the database. I'm using arrayRandom that stores left250 values and make it appear 90% of the time. arrayReallyRandom stores left250 values and appears 60% of the time. I have a combo box and a list of names. For eg. when i select Mark (the first name on the combo box), it will retrieve AC250L, store it as left250 and store it in arrayRandom and arrayReallyRandom. If user select 60% radiobutton, it will use values from arrayReallyRandom. Else if user select 90% radioButton, it will display values from arrayRandom. Let say, Mark's left250 value is 0, it will display values of 0 or 5. When i select the next name on the list, for eg. John, and John has a left250 value of 50, it should display values of 50 or 55. However, it always display 0 or 5. In fact, all the names is showing values of 0 or 5. How do i resolve that?
Expand|Select|Wrap|Line Numbers
- Dim randomObject As New System.Random()
- Private arrayRandom(9) As Integer
- Private arrayReallyRandom(9) As Integer
- Dim s As Integer
- 'AC
- Dim left250 As Integer
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- 'TODO: This line of code loads data into the 'SowmyaDataSet.thresholdTable' table. You can move, or remove it, as needed.
- Me.ThresholdTableTableAdapter.Fill(Me.SowmyaDataSet.thresholdTable)
- Dim con As New OleDb.OleDbConnection
- Dim ds As New DataSet
- Dim da As New OleDb.OleDbDataAdapter
- Dim sql As String
- con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Sowmya.mdb;Jet OLEDB:Database Password=geez"
- con.Open()
- sql = "SELECT * FROM thresholdTable"
- da = New OleDb.OleDbDataAdapter(sql, con)
- da.Fill(ds, "Sowmya")
- con.Close()
- s = Me.ComboBox1.SelectedIndex
- 'AC
- left250 = ds.Tables("Sowmya").Rows(s).Item("AC250L")
- '90%
- arrayRandom(0) = left250
- arrayRandom(1) = left250
- arrayRandom(2) = left250
- arrayRandom(3) = left250
- arrayRandom(4) = left250
- arrayRandom(5) = left250
- arrayRandom(6) = left250
- arrayRandom(7) = left250
- arrayRandom(8) = left250 + 5
- arrayRandom(9) = left250 + 5
- '60%
- arrayReallyRandom(0) = left250
- arrayReallyRandom(1) = left250
- arrayReallyRandom(2) = left250
- arrayReallyRandom(3) = left250
- arrayReallyRandom(4) = left250
- arrayReallyRandom(5) = left250
- arrayReallyRandom(6) = left250 + 5
- arrayReallyRandom(7) = left250 + 5
- arrayReallyRandom(8) = left250 + 5
- arrayReallyRandom(9) = left250 + 5
- End Sub
- Private Function randomNumber(ByVal rUpper As Integer, ByVal rLower As Integer) As Integer
- ' Generate random number between upper and lower bound values
- Randomize()
- randomNumber = Int(rUpper * Rnd() + rLower)
- End Function
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim RndNum As Integer
- If Me.RadioButton90.Checked = True Then
- RndNum = randomNumber(9, 0)
- Me.Label1.Text = arrayRandom(RndNum)
- ElseIf Me.RadioButton60.Checked = True Then
- RndNum = randomNumber(9, 0)
- Me.Label1.Text = arrayReallyRandom(RndNum)
- End If