Click here to Skip to main content
16,014,838 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralAccessing a database on a network drive Pin
ccotton3337-May-04 6:38
ccotton3337-May-04 6:38 
GeneralRe: Accessing a database on a network drive Pin
Dave Kreskowiak7-May-04 9:52
mveDave Kreskowiak7-May-04 9:52 
GeneralRandom Number Generator Pin
Britnt77-May-04 3:31
Britnt77-May-04 3:31 
GeneralRe: Random Number Generator Pin
Colin Angus Mackay7-May-04 3:59
Colin Angus Mackay7-May-04 3:59 
GeneralRe: Random Number Generator Pin
Britnt77-May-04 4:51
Britnt77-May-04 4:51 
GeneralRe: Random Number Generator Pin
Colin Angus Mackay7-May-04 5:02
Colin Angus Mackay7-May-04 5:02 
GeneralRe: Random Number Generator Pin
Britnt77-May-04 5:29
Britnt77-May-04 5:29 
GeneralRe: Random Number Generator Pin
Colin Angus Mackay7-May-04 12:08
Colin Angus Mackay7-May-04 12:08 
Britnt7 wrote:
Is it possible to pull from a list or array (1-50) so when the number is chosen, it is taken out of the list or array?

Yes, of course. Here is an example (It is a complete console application if you want to test it)

Module Module1

     Sub Main()
        ' Randomize the random number generator so it 
        ' produces different results each time
        Randomize()

        ' Declare variables
        Dim Array(4) As Integer
        Dim Counter As Integer
        Dim PossibleValues As ArrayList
        Dim Current As Integer
        Dim Index As Integer

        ' Build a list of possible values
        PossibleValues = New ArrayList(50)
        For Counter = 0 To 49
            PossibleValues.Add(Counter)
        Next

        ' Populate the Array of random values, removing
        ' each from the list of PossibleValues as they
        ' get used
        For Counter = 0 To 4
            Index = Int(PossibleValues.Count * Rnd())
            Current = CInt(PossibleValues(Index))
            Array(Counter) = Current
            PossibleValues.RemoveAt(Counter)
        Next

        'Print out the Array
        Array.Sort(Array)
        Console.WriteLine(Array(0))
        Console.WriteLine(Array(1))
        Console.WriteLine(Array(2))
        Console.WriteLine(Array(3))
        Console.WriteLine(Array(4))
        Console.ReadLine()
    End Sub

End Module


How it works is that a list of all possible values is built and as each possible value is randomly selected it is removed from the list of possible values. The Random number that is generated is used as the index into the list of PossibleValues. This technique could be used for any list of PossibleValues (say Months of the year, Days of the Week, Lottery Numbers, etc.) where you don't want to get the same value twice.

Does this help?


"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar

Coming soon: The Second EuroCPian Event


GeneralRe: Random Number Generator Pin
Britnt712-May-04 2:29
Britnt712-May-04 2:29 
GeneralRe: Random Number Generator Pin
Nick Seng12-May-04 0:02
Nick Seng12-May-04 0:02 
GeneralRe: Random Number Generator Pin
Britnt712-May-04 2:38
Britnt712-May-04 2:38 
GeneralRe: Random Number Generator Pin
Britnt712-May-04 3:23
Britnt712-May-04 3:23 
GeneralVB.NET Forms and Painting Pin
opopov6-May-04 22:08
opopov6-May-04 22:08 
GeneralRe: VB.NET Forms and Painting Pin
Syed Abdul Khader7-May-04 0:45
Syed Abdul Khader7-May-04 0:45 
GeneralRe: VB.NET Forms and Painting Pin
opopov7-May-04 5:29
opopov7-May-04 5:29 
GeneralRe: VB.NET Forms and Painting Pin
Syed Abdul Khader10-May-04 21:11
Syed Abdul Khader10-May-04 21:11 
Generalslideshow app in vb6 Pin
Ashwin C6-May-04 9:07
Ashwin C6-May-04 9:07 
GeneralRe: slideshow app in vb6 Pin
Dave Kreskowiak7-May-04 10:06
mveDave Kreskowiak7-May-04 10:06 
GeneralCom based add-in office Pin
skoizumi291106-May-04 6:01
sussskoizumi291106-May-04 6:01 
GeneralFrom C# to VB.Net Pin
Clandestine6-May-04 5:32
Clandestine6-May-04 5:32 
GeneralRe: From C# to VB.Net Pin
Dave Kreskowiak6-May-04 6:18
mveDave Kreskowiak6-May-04 6:18 
GeneralRe: From C# to VB.Net Pin
Clandestine7-May-04 3:30
Clandestine7-May-04 3:30 
GeneralVB6 Console APP Pin
gasma19755-May-04 14:42
gasma19755-May-04 14:42 
GeneralRe: VB6 Console APP Pin
Dave Kreskowiak5-May-04 15:04
mveDave Kreskowiak5-May-04 15:04 
GeneralRe: VB6 Console APP Pin
gasma19756-May-04 7:47
gasma19756-May-04 7:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.