473,605 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Random using Database

37 New Member
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. arrayReallyRand om 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 arrayReallyRand om. If user select 60% radiobutton, it will use values from arrayReallyRand om. 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 1111

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

Similar topics

6
2393
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 key and send it via Email. Well after finding out about PHP, and that my host does PHP, I thought it would be quicker and more reliable to generate the keys on the server and send them out again either vai email or from the sales site.
4
6280
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 subject and then select a random set of records meeting that subject. Any ideas or thought would be helpful. I'm using Access XP to try this out. TIA
3
3229
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
3103
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 wrapped in duck tape with a few diodes and two wires sticking out. When attaching the wires to your skin the diodes would light up in a random configuration. (he later modified this into a skin resistance
22
17860
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
5161
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 4,294,967,295. Suppose the PRIMARY key data type is set to "RANDOM" AutoNumber. Suppose an application (a) successfully INSERTS "X" records, then (b) successfully DELETES "Y" records (X >= Y), then
2
2508
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 system will store user's info such as name, student id number, log on time, log out time into a database file, when the next student log on, the function loads the database, and compare the random generated machine id with the existing ids store...
4
2388
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 of making a case statement with 26 options, is there a more streamlined way to get an integer between 1-26 translated into one of the letters?
3
3875
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
2536
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 then generate again and store new number in to database. I have created 10 label in the form which display the random number and at the same time I want random number generated to be stored in database. I don’t know how to start Plz help me with...
0
8004
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7934
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8425
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6743
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3912
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3958
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2438
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1541
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.