silentwraith

New Member
Joined
Apr 6, 2019
Messages
1
Hi all, I am a newbie to VBA and would love to know your suggestions on how I can solve the following problem I am facing in the program. I am struggling to implement logic to start a new game once the user has guessed the number. I am attaching the program that I wrote and would love to hear any other suggestions. Cheers!


Code:
Dim SecretNumber As Integer

Private Sub GuessButton_Click()
GuessButton.Font.Bold = True
    If IsNumeric(GuessInput.Value) = False Then
        Information.Caption = "Please enter a valid number!"
        GuessInput.Value = ""
    ElseIf GuessInput.Value < 0 Or GuessInput.Value > 100 Then
        Information.Caption = "Please enter a number from 1 to 100"
        GuessInput.Value = ""
    ElseIf GuessInput.Value < SecretNumber Then
        Information.Caption = "The guess is too small >.<"
        GuessInput.Value = ""
    ElseIf GuessInput.Value > SecretNumber Then
        Information.Caption = "The guess is too big >.<"
        GuessInput.Value = ""
    Else ' By now, the guess must be the secret number
        Information.Caption = "Here here, you have guessed the number! :D "
        


    'set up the controls so that the player can start a new game
    End If
End Sub


Private Sub Label_Click()
Label.Font.Bold = True
Label.TextAlign = fmTextAlignCenter
End Sub


Private Sub StartButton_Click()
    
    StartButton.Enabled = False
    Information.Caption = "Put your guess in the box and press the button!"
    GuessButton.Enabled = True
    GuessInput.Enabled = True
    GuessInput.Value = ""
    
    StartButton.Font.Bold = True
    Randomize (SecretNumber)
    SecretNumber = Int(Rnd * 100) + 1
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Maybe a message box that ask "Do you want to play again?" with Yes No buttons. If yes call the sub again
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,972
Members
448,933
Latest member
Bluedbw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top