Random function 1 - 4

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • I Hate My Computer
    New Member
    • Mar 2007
    • 44

    Random function 1 - 4

    I need to create a random code to run a function 1 - 4. i.e. random number is 1 so it runs function 1 random number is 2 so it runs function 2. I would like to have this in VBA because that is all I have.

    Thanks for your support.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by I Hate My Computer
    I need to create a random code to run a function 1 - 4. i.e. random number is 1 so it runs function 1 random number is 2 so it runs function 2. I would like to have this in VBA because that is all I have.
    Generate a value into a variable using the rnd function, then use Select Case to make the decision.

    Comment

    • I Hate My Computer
      New Member
      • Mar 2007
      • 44

      #3
      Originally posted by Killer42
      Generate a value into a variable using the rnd function, then use Select Case to make the decision.
      When you say that do you mean something like this:

      Code:
      Select Case KeyCode
      Case vbKeyEscape
          End
          GO.Visible = False
      Case vbKeyLeft
          G_Ship.Left = (G_Ship.Left - 18)
      Case vbKeyRight
          GO.Visible = False
          G_Ship.Left = (G_Ship.Left + 18)
      Case vbKeyUp
          GO.Visible = False
          G_Ship.Top = (G_Ship.Top - 18)
      Case vbKeyDown
          GO.Visible = False
          G_Ship.Top = (G_Ship.Top + 18)
      End Select
      If so is their something I should put as the case. If not can you give me an example?

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by I Hate My Computer
        When you say that do you mean something like this:
        Code:
        Select Case KeyCode
        Case vbKeyEscape
            End
            [B]GO.Visible = False[/B]
        ...
        End Select
        If so is their something I should put as the case. If not can you give me an example?
        You said that you needed to "create a random code to run a function", not use a keypress. What I was suggesting was something like...
        Code:
        MyNumber = RND * 4 ' <-- Probably not quite correct.
        Select Case MyNumber
          Case 1
            Do function 1
          Case 2
            Do function 2
          Case 3
            Do function 3
          Case 4 ' Or "Case Else"
            Do function 4
        End Select
        By the way, any statement following the End statement, such as the one I highlighted above, will not be executed. End causes the program to end immediately.

        Comment

        • I Hate My Computer
          New Member
          • Mar 2007
          • 44

          #5
          Originally posted by Killer42
          You said that you needed to "create a random code to run a function", not use a keypress. What I was suggesting was something like...
          Code:
          MyNumber = RND * 4 ' <-- Probably not quite correct.
          Select Case MyNumber
            Case 1
              Do function 1
            Case 2
              Do function 2
            Case 3
              Do function 3
            Case 4 ' Or "Case Else"
              Do function 4
          End Select
          By the way, any statement following the End statement, such as the one I highlighted above, will not be executed. End causes the program to end immediately.
          I understand I was asking about how to do the case. I will be sure to take your example into consideration.

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by I Hate My Computer
            I understand I was asking about how to do the case. I will be sure to take your example into consideration.
            Cool.

            Hope it works out.

            Comment

            Working...