Re: Enumerations And Random Numbers
From: Herfried K. Wagner [MVP] (hirf-spam-me-here_at_gmx.at)
Date: 10/30/04
- Next message: Larry Serflaten: "Re: Enumerations And Random Numbers"
- Previous message: Herfried K. Wagner [MVP]: "Re: Flat button"
- In reply to: One Handed Man \( OHM - Terry Burns \): "Enumerations And Random Numbers"
- Next in thread: Larry Serflaten: "Re: Enumerations And Random Numbers"
- Reply: Larry Serflaten: "Re: Enumerations And Random Numbers"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 30 Oct 2004 12:54:16 +0200
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> schrieb:
> If I have an enumeration such as this
>
> Fiend Enum TravelDirection
> North
> South
> East
> West
> End Enum
>
> and
>
> Direction = TravelDirection
>
> Now I want to set the Direction Randomly to one of the TravelDirection
> enum values
>
> If I know that my enum is between 1 and 4 I can easily get a new random
> number and assign it, however, As I add to the enumeration, I wont want to
> worry about coding all the changes, so how could I easily do this I know
> I can do it, and I have but Im looking for the most simple solution.
\\\
Dim Values() As AnchorStyles = [Enum].GetValues(GetType(AnchorStyles))
Dim r As New Random
MsgBox(Values(r.Next(0, Values.Length - 1)).ToString())
///
-- Herfried K. Wagner [MVP] <URL:http://dotnet.mvps.org/>
- Next message: Larry Serflaten: "Re: Enumerations And Random Numbers"
- Previous message: Herfried K. Wagner [MVP]: "Re: Flat button"
- In reply to: One Handed Man \( OHM - Terry Burns \): "Enumerations And Random Numbers"
- Next in thread: Larry Serflaten: "Re: Enumerations And Random Numbers"
- Reply: Larry Serflaten: "Re: Enumerations And Random Numbers"
- Messages sorted by: [ date ] [ thread ]