Re: Enumerations And Random Numbers

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Larry Serflaten (serflaten_at_usinternet.com)
Date: 10/30/04


Date: Sat, 30 Oct 2004 06:12:04 -0500


"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote
> I have a basic question thats been niggling me, but I never found time to
> look at it before.
>
>
> If I have an enumeration such as this
>
> Fiend Enum TravelDirection
> North
> South
> East
> West
> End Enum
>
> and
>
> Direction = TravelDirection

That should be:

  Direction = TravelDirection.East

Or some other specific value. You wouldn't be able to assign the
entire enum to a variable.

> 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. There
> doesent seem to be a Max property for enumerations.

Why not use one of the values?

> East
> West
           MaxDirection = West
> End Enum

LFS


Quantcast