PDA

View Full Version : [SOLVED:] Random Name Selector



Waubain
11-08-2011, 01:43 PM
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.

John Wilson
11-09-2011, 04:03 AM
There's an example of one way to do this here
http://www.pptalchemy.co.uk/powerpoint_hints_and_tips_tutorials.html#random

Waubain
11-09-2011, 07:10 AM
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

John Wilson
11-10-2011, 09:14 AM
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