473,385 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Random using Database

37
Hi there,
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
  1. Dim randomObject As New System.Random()
  2.     Private arrayRandom(9) As Integer
  3.     Private arrayReallyRandom(9) As Integer
  4.     Dim s As Integer
  5.  
  6.  
  7.     'AC
  8.     Dim left250 As Integer
  9.  
  10.  
  11.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  12.  
  13.   'TODO: This line of code loads data into the 'SowmyaDataSet.thresholdTable' table. You can move, or remove it, as needed.
  14.         Me.ThresholdTableTableAdapter.Fill(Me.SowmyaDataSet.thresholdTable)
  15.  
  16.         Dim con As New OleDb.OleDbConnection
  17.         Dim ds As New DataSet
  18.         Dim da As New OleDb.OleDbDataAdapter
  19.         Dim sql As String
  20.  
  21.         con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Sowmya.mdb;Jet OLEDB:Database Password=geez"
  22.  
  23.  
  24.         con.Open()
  25.  
  26.         sql = "SELECT * FROM thresholdTable"
  27.         da = New OleDb.OleDbDataAdapter(sql, con)
  28.         da.Fill(ds, "Sowmya")
  29.  
  30.         con.Close()
  31.  
  32.         s = Me.ComboBox1.SelectedIndex
  33.  
  34.         'AC
  35.         left250 = ds.Tables("Sowmya").Rows(s).Item("AC250L")
  36.  
  37.  
  38.         '90%
  39.         arrayRandom(0) = left250
  40.         arrayRandom(1) = left250
  41.         arrayRandom(2) = left250
  42.         arrayRandom(3) = left250
  43.         arrayRandom(4) = left250
  44.         arrayRandom(5) = left250
  45.         arrayRandom(6) = left250
  46.         arrayRandom(7) = left250
  47.         arrayRandom(8) = left250 + 5
  48.         arrayRandom(9) = left250 + 5
  49.  
  50.         '60%
  51.         arrayReallyRandom(0) = left250
  52.         arrayReallyRandom(1) = left250
  53.         arrayReallyRandom(2) = left250
  54.         arrayReallyRandom(3) = left250
  55.         arrayReallyRandom(4) = left250
  56.         arrayReallyRandom(5) = left250
  57.         arrayReallyRandom(6) = left250 + 5
  58.         arrayReallyRandom(7) = left250 + 5
  59.         arrayReallyRandom(8) = left250 + 5
  60.         arrayReallyRandom(9) = left250 + 5
  61.  
  62.     End Sub
  63.  
  64.     Private Function randomNumber(ByVal rUpper As Integer, ByVal rLower As Integer) As Integer
  65.  
  66.         ' Generate random number between upper and lower bound values
  67.         Randomize()
  68.         randomNumber = Int(rUpper * Rnd() + rLower)
  69.     End Function
  70.  
  71.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  72.  
  73.         Dim RndNum As Integer
  74.  
  75.  
  76.         If Me.RadioButton90.Checked = True Then
  77.             RndNum = randomNumber(9, 0)
  78.             Me.Label1.Text = arrayRandom(RndNum)
  79.  
  80.         ElseIf Me.RadioButton60.Checked = True Then
  81.             RndNum = randomNumber(9, 0)
  82.             Me.Label1.Text = arrayReallyRandom(RndNum)
  83.  
  84.         End If
Aug 15 '07 #1
0 1096

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Trythat | last post by:
This might seem a stupid question but here goes - I wrote a key generator for one of my programs in Visual Basic, so I recieve sales notification via email and then use my program to generate the...
4
by: Keith Griffiths | last post by:
I'm trying to do a search under a set criteria followed by a selection of random entries meeting this criteria. But I don't seem to be able to achieve this. The idea being to search on say...
3
by: Andie | last post by:
Hello All, How would I go about using a disconnect recordset and select (x) records from it, x being the number of records to be selected. Many thanks in advance. -- Andie
5
by: Luke | last post by:
Hello, I am the administrator for http://www.nickberg.org - Nick is the man who was recently beheaded in Iraq. He was a very ingenious man - once for my birthday had gave me a small box...
22
by: Nhmiller | last post by:
Is there a way to do this? Thanks. Neil Cat Paintings At Carol Wilson Gallery http://www.carolwilsongallery.com
4
by: yf | last post by:
A KB article "http://support.microsoft.com/default.aspx?scid=kb;en-us;209599" tells that the maximum number of records that a table may hold if the PRIMARY key data type is set to AUTONUMBER is...
2
by: sugaray | last post by:
I want to write a school computer billing system, one of the function is to distribute machine id using rand() for each student log on, suppose there's 100 machines, when each person log on, the...
4
by: darrel | last post by:
I can grab a random number in vb.net like this: Dim RandomClass As New Random Dim RandomNumber As Integer RandomNumber = RandomClass.Next(1, 26) However, what I want is a random number. Short...
3
by: John Fairhurst | last post by:
Hi, The following code should select the specified number of records randomly from the database <% .... query = "SELECT FROM " Set RS = Server.CreateObject("ADODB.Recordset")
5
by: JuAn2226 | last post by:
How do I create database which will store the random number that generated before I reset the random number and how do I check that new random number after I reset is exists in database. If exist...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.