Answered step by step
Verified Expert Solution
Question
00
1 Approved Answer
Hello, I am making a guessing game in excel. I have completed the construction of the basic framework ( such as text box settings, start
Hello, I am making a guessing game in excel. I have completed the construction of the basic framework such as text box settings, start and end button settings but have not completed writing the VBA code. Please help me follow the following requirements. Complete the VBA code. grateful. The game itself is a very simple game. At the start of the game, the computer thinks of a secret number between and The player then has to guess the number correctly using as few guesses as possible. You will clear the game display in the workbook open event. First, you need to clear the text inside the number input cell at the start. You can do that by clearing the Value property of the cell, like this: WorksheetsGameRangeNumberValue Then, you need to clear the information display so that the game can put some useful information there later. This is a little tricky as the text display is an Excel text shape. To change the text content of an Excel text shape you need to change the TextFrame of the shape, like this: WorksheetsGameShapesHintTextFrame.Characters.Text new content... The above line of code is very long but it is only a simple property of the Excel shape for changing its text content. At the start of the game, the computer needs to think of a secret number. This number will be between and inclusive. You can generate such a number using VBA code easily, using Randomize and Rnd that you have used. You can create a global variable by putting the following line at the very top of the code area, outside of any macro: Dim SecretNumber As Integer Let's emphasize again that the above line of code has to be put at the top of the code area, instead of inside any function or subroutine. The variable that the above line of code creates is called SecretNumber. You will use this variable to store the random number and you will use this variable throughout the rest of the game. The final task of this exercise is to check the player's guess. The player makes hisher guess by entering the number in the number input cell and then clicking on the 'Make My Guess! button. Therefore, the VBA code that you will use to check the guess should go inside the MakeMyGuess macro of the 'Make My Guess! button. Inside the macro, you need to check the following situations based on the player's input: If the guess is not a valid number If the guess is not inside the range of and If the guess is smaller than SecretNumber If the guess is bigger than SecretNumber Otherwise, the guess must be SecretNumber As you can see, the above situations can be represented in a very big IfElseIf...Else statement, ie If the guess is not a valid number... Then Hint some message... ElseIf the guess is not within to Then Hint some message... ElseIf the guess is smaller than the secret number... Then Hint some message... ElseIf the guess is bigger than the secret number... Then Hint some message... Else By now, the guess must be the secret number Hint some message... End If Put the Hint into the information display... When the player correctly guesses the secret number, the game is over. You need to tell the player that heshe has finished the game using the information text display so that the player can start the game again. You don't need to clear the content of the number input cell or the information text display because the player still needs to know that heshe has finished the game by reading the information content.
Hello, I am making a guessing game in excel. I have completed the construction of the basic framework such as text box settings, start and end button settings but have not completed writing the VBA code. Please help me follow the following requirements. Complete the VBA code. grateful.
The game itself is a very simple game. At the start of the game, the computer thinks of a secret number between and The player then has to guess the number correctly using as few guesses as possible.
You will clear the game display in the workbook open event.
First, you need to clear the text inside the number input cell at the start. You can do that by clearing the Value property of the cell, like this:
WorksheetsGameRangeNumberValue
Then, you need to clear the information display so that the game can put some useful information there later.
This is a little tricky as the text display is an Excel text shape. To change the text content of an Excel text shape you need to change the TextFrame of the shape, like this:
WorksheetsGameShapesHintTextFrame.Characters.Text new content...
The above line of code is very long but it is only a simple property of the Excel shape for changing its text content.
At the start of the game, the computer needs to think of a secret number. This number will be between and inclusive. You can generate such a number using VBA code easily, using Randomize and Rnd that you have used.
You can create a global variable by putting the following line at the very top of the code area, outside of any macro:
Dim SecretNumber As Integer
Let's emphasize again that the above line of code has to be put at the top of the code area, instead of inside any function or subroutine. The variable that the above line of code creates is called SecretNumber. You will use this variable to store the random number and you will use this variable throughout the rest of the game.
The final task of this exercise is to check the player's guess. The player makes hisher guess by entering the number in the number input cell and then clicking on the 'Make My Guess! button. Therefore, the VBA code that you will use to check the guess should go inside the MakeMyGuess macro of the 'Make My Guess! button.
Inside the macro, you need to check the following situations based on the player's input:
If the guess is not a valid number
If the guess is not inside the range of and
If the guess is smaller than SecretNumber
If the guess is bigger than SecretNumber
Otherwise, the guess must be SecretNumber
As you can see, the above situations can be represented in a very big IfElseIf...Else statement, ie
If the guess is not a valid number... Then
Hint some message...
ElseIf the guess is not within to Then
Hint some message...
ElseIf the guess is smaller than the secret number... Then
Hint some message...
ElseIf the guess is bigger than the secret number... Then
Hint some message...
Else By now, the guess must be the secret number
Hint some message...
End If
Put the Hint into the information display...
When the player correctly guesses the secret number, the game is over. You need to tell the player that heshe has finished the game using the information text display so that the player can start the game again.
You don't need to clear the content of the number input cell or the information text display because the player still needs to know that heshe has finished the game by reading the information content.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started