Consulting

Results 1 to 3 of 3

Thread: Unique random number from array, VBA

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    VBAX Newbie
    Joined
    Apr 2021
    Posts
    2
    Location
    Thanks for the reply! I am going to check it out! So far i made this bit of code work for 5 players with 3 roles (2 of wich duplicated):

    Sub RRS()
    Dim flag As Boolean
    flag = True
    While flag
    Randomize
    Randomnumber = Int((5 * Rnd) + 1)
    If Randomnumber = 1 And Slide5.a1.Caption = 0 Then
    Slide5.a1.Caption = 1
    ActivePresentation.SlideShowWindow.View.GotoSlide (7)
    flag = False
    ElseIf Randomnumber = 2 And Slide5.a2.Caption = 0 Then
    Slide5.a2.Caption = 1
    ActivePresentation.SlideShowWindow.View.GotoSlide (7)
    flag = False
    ElseIf Randomnumber = 3 And Slide5.a3.Caption = 0 Then
    Slide5.a3.Caption = 1
    ActivePresentation.SlideShowWindow.View.GotoSlide (8)
    flag = False
    ElseIf Randomnumber = 4 And Slide5.a4.Caption = 0 Then
    Slide5.a4.Caption = 1
    ActivePresentation.SlideShowWindow.View.GotoSlide (8)
    flag = False
    ElseIf Randomnumber = 5 And Slide5.a5.Caption = 0 Then
    Slide5.a5.Caption = 1
    ActivePresentation.SlideShowWindow.View.GotoSlide (9)
    flag = False
    ElseIf Slide5.a1.Caption = 1 And Slide5.a2.Caption = 1 And Slide5.a3.Caption = 1 And Slide5.a4.Caption = 1 And Slide5.a5.Caption = 1 Then
    MsgBox "Press Play!"
    flag = False
    End If
    Wend
    End Sub

    Nothing fancy for sure, but that works heh. I also made a logic using arrays but was struggling with their syntax. Stuff like UBound(Rarray) - LBound(Rarray) + 1 instead of array length; Redim and so on.
    Thanks again for looking into it and showing good solution!
    Last edited by Maxim33; 04-23-2021 at 11:57 AM. Reason: formating

Posting Permissions

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