views:

333

answers:

2

Hallo! I'm a n00b, and I'm looking for a few lines of code in VB6 to implement this: I want to list a certain number of commands to execute, then tell my program to chose a random one among them and execute it: strictly speaking, I'm dealing with a MSAgent character, and I want him to make a face every 5 minutes. How can I achieve this, please?

+2  A: 
Public Sub MakeFace()

  'Reset random seed.
  Randomize

  'Generate a random integer with the specified range.
  Dim Min As Integer, Max As Integer, N As Integer
  Min = 1
  Max = 5
  N = Min + Round(Rnd) * Max

  'Select and call the desired function.
  Select Case N

    Case 1
      Call MakeHappyFace

    Case 2
      Call MakeSadFace

    Case 3
      Call MakeAngryFace

    Case 4
      Call MakeSmirkFace

    Case 5
      Call MakeFunnyFace

  End Select

End Sub
JRS
Isn't Round(Rnd) always 0 or 1?
recursive
A: