| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Guessing Game (VBA using Excel)

Page history last edited by PBworks 16 years, 10 months ago

Public Sub GuessingGame()

Dim Secret As Integer

Dim Guess As Integer

Dim Tries As Integer

 

Randomize  'Inittializes random-number generator

 

Secret = Int((100 * Rnd) + 1) 'Generates a random number between 1 and 100

 

Guess = 0

Tries = 0

 

Do While Guess <> Secret

Guess = InputBox("Guess a number bewteen 1 and 100.")

If Guess = Secret Then

    Tries = Tries + 1

    MsgBox ("Well done! You guessed the number.")

    MsgBox ("It took you " & Tries & " to guess the number")

ElseIf Guess > Secret Then

    Tries = Tries + 1

    MsgBox ("Wrong. Too high. Try again.")

Else

    Tries = Tries + 1

    MsgBox ("Wrong. Too low. Try again.")

End If

Loop

End Sub

Comments (0)

You don't have permission to comment on this page.