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