# How to show how many guesses they used

Page 1 of 1

## 1 Replies - 885 Views - Last Post: 09 February 2009 - 02:58 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=85559&amp;s=0febbfcb90c9a57a0dbe0c3855c5f893&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 MonkeyBoy2194

• D.I.C Regular

Reputation: 3
• Posts: 489
• Joined: 09-February 09

# How to show how many guesses they used

Posted 09 February 2009 - 02:42 AM

The code's working fine I just don't know how to show how many times the user entered a number

Dim Number As Integer
Dim RandomNumber As Integer
Dim guesses As Integer
Private Sub cmdClear_Click()

msg.Cls

End Sub

Private Sub cmdQuit_Click()

End

End Sub

Private Sub cmdStart_Click()

Randomize Timer
RandomNumber = Int(Rnd * 20) + 1
Do
Do
Number = Val(InputBox("Please enter a whole number between 1 to 20"))

If Number <= 1 Then MsgBox ("Please enter a valid number")
If Number >= 20 Then MsgBox ("Please enter a valid number")
Loop Until Number = Valid Or Number > 1 Or Number < 20

Counter = Counter + 1

If Number > RandomNumber Then MsgBox ("The Number you entered is too high.")
If Number < RandomNumber Then MsgBox ("The number you entered is too low.")

Loop Until Number = RandomNumber

MsgBox ("That is the correct number, well done=]")

Is This A Good Question/Topic? 0

### #3 thepeoplescoder

Reputation: 17
• Posts: 97
• Joined: 02-February 09

## Re: How to show how many guesses they used

Posted 09 February 2009 - 02:58 AM

MonkeyBoy2194, on 9 Feb, 2009 - 01:42 AM, said:

The code's working fine I just don't know how to show how many times the user entered a number

```Dim Number As Integer
Dim RandomNumber As Integer
Dim guesses As Integer
Private Sub cmdClear_Click()

msg.Cls

End Sub

Private Sub cmdQuit_Click()

End

End Sub

Private Sub cmdStart_Click()

Randomize Timer
RandomNumber = Int(Rnd * 20) + 1
Do
Do
Number = Val(InputBox("Please enter a whole number between 1 to 20"))

If Number <= 1 Then MsgBox ("Please enter a valid number")
If Number >= 20 Then MsgBox ("Please enter a valid number")
Loop Until Number = Valid Or Number > 1 Or Number < 20

Counter = Counter + 1

If Number > RandomNumber Then MsgBox ("The Number you entered is too high.")
If Number < RandomNumber Then MsgBox ("The number you entered is too low.")

Loop Until Number = RandomNumber

MsgBox ("That is the correct number, well done=]")

```

Do the following to the cmdStart_Click() sub.

At the beginning, add Dim Counter As Integer and Dim Congrats As String

At your message box that lets the user know they entered the correct number, replace it with this.
```Congrats = "That is the correct number, well done=]" + Chr\$(13) + Chr\$(10)
Congrats = Congrats + "It took you" + Str\$(Counter) + " tries."
MsgBox(Congrats)

```