Program that generates and puts..
Program that generates and puts..
Program that generates and puts..
Program that generates and puts..
Program that generates and puts..
Program that generates and puts.. Program that generates and puts.. Program that generates and puts.. Program that generates and puts.. Program that generates and puts.. Program that generates and puts.. Program that generates and puts.. Program that generates and puts..
Program that generates and puts.. Program that generates and puts..
Program that generates and puts..
Go Back  Xtreme Visual Basic Talk > > > Program that generates and puts..


Reply
 
Thread Tools Display Modes
  #1  
Old 01-05-2010, 03:38 PM
valme valme is offline
Newcomer
 
Join Date: Jan 2010
Posts: 2
Default Program that generates and puts..


Hi, im new to Vb and i would really need help. I need to create a program that would do something like this.

you choose two numbers, for example 10 and 3, number 3 stands for how many numbers each row has, for example 1st row has numbers 2,3,5. Number 10 shows how many numbers will be generated, so number between 1 to 10. If any number was left out, program shows you that. In each row all the numbers will have to be sorted so their value would go up, like 2,3,5, they cant be mixed like 5,2,3.


1st row has nr : 2,3,5
2nd row has nr : 4,6,8
3rd row has nr : 1,7,10
Left out: 9


right now i have something like this

Dim L, A, S As Integer
A = TextBox1.Text
S = TextBox2.Text
Dim V(A - 1) As Boolean
For i = 0 To A - 1
Do
L = Int(S * Rnd())
Loop While V(L) = True
V(L) = True

Next
For i = 0 To S - 1
If V(i) = True Then ListBox1.Items.Add(i + 1)
Next

but i cant figure out how to make generate numbers from 1 -10 for example without leaving any numbers out and how to make sure that numbers wount repeated. Sry about my bad English.

Last edited by valme; 01-05-2010 at 04:17 PM.
Reply With Quote
  #2  
Old 01-06-2010, 12:23 AM
valme valme is offline
Newcomer
 
Join Date: Jan 2010
Posts: 2
Default

anyone?

i would really need help, so program would generate numbers, like this

1st row has nr : 2,3,5
2nd row has nr : 4,6,8
3rd row has nr : 1,7,10
Left out: 9


no matter range of numbers i choose. what would be the code for creating rows
Reply With Quote
  #3  
Old 01-06-2010, 03:58 PM
Iceplug's Avatar
IceplugProgram that generates and puts.. Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

OK, first of all, asking for code may draw people away.
Second of all, I'm not sure if I understand what you are doing here, because you seem to be providing only one example of what you want to do.
Quote:
you choose two numbers, for example 10 and 3,
number 3 stands for how many numbers each row has
10 corresponds to A and 3 corresponds to S?
So, you choose how many numbers each row has. But how many rows do you have?
Do you just generate numbers until you run out of numbers to fill another row?
In that case, you'll always have a number of rows equal to A \ S, where \ is integer division of the two numbers and no fraction/remainder is regarded.
So 10 \ 3 = 3R1 without the R1 so it is just 3.

Thirdly, random number generators will generate repeating numbers. Your program has to generate the non-repeating number based on numbers that could repeat.
A way (not exactly simple) would require using an array containing possible numbers to use (or a collection if you like them).
The issue here: You have an array containing the numbers you want to use:
Dim Nums(9) As Integer
Nums = 0 1 2 3 4 5 6 7 8 9 'Pretend that this is your array.
Dim NumCount As Integer
NumCount = 10 'Pretend that this holds the number of numbers in your array.
Generate a random number
R = Int(Rnd * NumCount) 'Let's say R is 4, because R is a random number less than 10.
RNum = Nums(R) 'Nums(4) is 4... for now!

You then remove 4 from the array using a For Loop
For LV = R + 1 To NumCount - 1
Nums(LV - 1) = Nums(LV)
Loop
What this does if you step through it slowly:
0 1 2 3 4 5 6 7 8 9 (Loop goes from R + 1 which is 5, and NumCount - 1 which is 9)
We take the number at the position of LV - 1 (first time this is position 4) and replace it with the number at the position of LV (first time this is position 5)
so, the array will do this:
0 1 2 3 5 5 6 7 8 9
LV is incremented by 1 and the process occurs again.

When LV = 5, 0 1 2 3 5 6 6 7 8 9
When LV = 6, 0 1 2 3 5 6 7 7 8 9
When LV = 7, 0 1 2 3 5 6 7 8 8 9
When LV = 8, 0 1 2 3 5 6 7 8 9 9 (notice the number 4 is gone!)
Once you are done, reduce NumCount by 1.
NumCount = NumCount - 1
Now, to generate the next random number, you do the same thing that you did earlier:

R = Int(Rnd * NumCount)
But now, NumCount is 9, so R will be a random number less than 9.
Let's say you picked 6.
RNum = Nums(R) 'Nums(6) does not correspond to 6... it corresponds to 7.
Look back at the array values after the loop.
0 1 2 3 5 6 7 8 9 9 (notice the number 4 is gone!)
Now that RNum is 6, you pick 7.

You then remove the 7 from the array using a For Loop
Remember thatt R refers to the index of the array whereas RNum refers to the random number retrieved from the array.
For LV = R + 1 To NumCount - 1
Nums(LV - 1) = Nums(LV)
Loop
This will remove the 7 from the array.
0 1 2 3 5 6 8 9 9 9
And you decrease the value of NumCount again to 8.

You pick another random number
R = Int(Rnd * NumCount)
This time, R must be less than 8. Let's say 4. Remember that Rnd can generate as many repeating numbers as it wants to. It is your task to ensure that numbers that you use don't repeat.
RNum = Nums(R) You can figure out which number this is, yes/no?
Remove number from the array
0 1 2 3 6 8 9 9 9 9

If you noticed all of the 9s at the top of the array, don't worry, only one can be picked from Rnd because we continually decrease the value of NumCount, ensuring that those extra 9s are at an index that is too high to be generated by the current value of NumCount.
So, you generate a bunch of random numbers and you get down to a point where you only have a few more choices left.
This is what your array *could* look like when NumCount is 3.
1 6 8 9 9 9 9 9 9 9
What numbers are left over? Why, the first three numbers are left over.
That would be 1, 6, and 8.
If NumCount is 2, you could have this.
2 9 9 9 9 9 9 9 9 9
In this case, 2 and 9 are left over, because they are the first two numbers of the array.
When NumCount is 1, what number is left over?
4 9 9 9 9 9 9 9 9 9
Answer: 4
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Program that generates and puts..
Program that generates and puts..
Program that generates and puts.. Program that generates and puts..
Program that generates and puts..
Program that generates and puts..
Program that generates and puts.. Program that generates and puts.. Program that generates and puts.. Program that generates and puts.. Program that generates and puts.. Program that generates and puts.. Program that generates and puts..
Program that generates and puts..
Program that generates and puts..
 
Program that generates and puts..
Program that generates and puts..
 
-->