Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleMake a random choice using the PickOne function
Keywordspick one, PickOne, random
CategoriesAlgorithms, Tips and Tricks
 
The PickOne function lets you quickly pick an item from a fixed list as in:

    lblResult.Caption = PickOne("Program", "Debug", "Email", "Write")
 
' Return a randomly selected argument.
Private Function PickOne(ParamArray choices() As Variant) _
    As Variant
Dim min_i As Integer
Dim max_i As Integer
Dim rnd_i As Integer

    min_i = LBound(choices)
    max_i = UBound(choices)
    rnd_i = Int((max_i - min_i + 1) * Rnd + min_i)
    PickOne = choices(rnd_i)
End Function
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated