Waubain
09-10-2010, 09:36 AM
During a lecture I click on a button on a slide and a name is randomly picked from a list and displayed on the screen. Below is the code. The problem is that the random selection is always in the same order every time I start the slide presentation. This might be how the random is seeded? I have about 100 student names in the text file.
Is there a way to make the seed random, so the order is always different each time the presentation starts.
Thanks.
----------------------------
Private Sub UserForm_Initialize()
Me.StartUpPosition = 0 'From Top Left
Me.Top = 310
Me.Left = 450
Dim arr, fs, a
Dim ThePath As String
Dim NewPath As String
Dim name As String
ThePath = CurDir ' Returns Path of lecture
NewPath = ThePath & "\names\names.txt" ' Creates a new path where names are located
Set fs = CreateObject("Scripting.FileSystemObject") ' Chooses a random student from text file
Set a = fs.openTextFile(NewPath)
arr = Split(a.readall, Chr(13) & Chr(10))
name = arr(Int((112 * Rnd)))
lblName.Caption = name ' displays name in label caption
End Sub
Private Sub cmdOK_Click()
Dim SlideNumber As Long
Unload frmName ' unloads form from memory
End Sub
Is there a way to make the seed random, so the order is always different each time the presentation starts.
Thanks.
----------------------------
Private Sub UserForm_Initialize()
Me.StartUpPosition = 0 'From Top Left
Me.Top = 310
Me.Left = 450
Dim arr, fs, a
Dim ThePath As String
Dim NewPath As String
Dim name As String
ThePath = CurDir ' Returns Path of lecture
NewPath = ThePath & "\names\names.txt" ' Creates a new path where names are located
Set fs = CreateObject("Scripting.FileSystemObject") ' Chooses a random student from text file
Set a = fs.openTextFile(NewPath)
arr = Split(a.readall, Chr(13) & Chr(10))
name = arr(Int((112 * Rnd)))
lblName.Caption = name ' displays name in label caption
End Sub
Private Sub cmdOK_Click()
Dim SlideNumber As Long
Unload frmName ' unloads form from memory
End Sub