Consulting

Results 1 to 4 of 4

Thread: Random Name Selector

  1. #1
    VBAX Regular
    Joined
    Apr 2010
    Posts
    21
    Location

    Random Name Selector

    I have a button on my slides that randomly picks a name from a list. When I had over 100 students it rarely called on a student twice. Now I have a class with less than ten and the names are duplicated too often. What I would like to do now is after a name has been selected that name is dropped from the list, but when one name is left, then the array is repopulated with the original list of names. The names need to continue to be in a random order no matter how many times the list is repopulated. I do not know where to start. It seems that either I need a second arrary or some loop or both. Here is my current code:


    Private Sub UserForm_Initialize() 
    Me.StartUpPosition = 0 'From Top Left 
    Me.Top = 10 
    Me.Left = 30 
    Dim arr 
    Dim name As String 
    ' Chooses a random student from a list 
    arr = Array("Bob", "Ted", "Carole", "Alice") 
    seed = TimeValue("00:" & Format(Second(Time), "00") & ":" & Format(Minute(Time), "00")) 
    Randomize (seed) name = arr(Int((4 * Rnd))) 
    ' displays name in label caption 
    lblName.Caption = name 
    End Sub
    Thank you in advance.
    Last edited by Aussiebear; 04-11-2023 at 06:08 AM. Reason: Adjusted the code tags

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    There's an example of one way to do this here
    http://www.pptalchemy.co.uk/powerpoi...ls.html#random
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Regular
    Joined
    Apr 2010
    Posts
    21
    Location
    John,

    Thank you for the link. This is a great start. I want to continue to use a UserForm as I like bigger print than a Msgbox. I expect that I can create a Yes/No UserForm and work that into the code along with my current frmName rather than the Msgbox's. Thank's again.

    Bob

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Easy enough to do that but why not just get the code to update a standard text box on the slide. You can have any size text then.

    eg

    ActivePresentation.Slides(1).Shapes(3).TextFrame.TextRange=name
    Last edited by Aussiebear; 04-11-2023 at 06:09 AM. Reason: Added code tags
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •