Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Enhancements to Number of Guess

Posted on 2007-12-05
6
Medium Priority
?
380 Views
Last Modified: 2008-02-01
I have a Guess the Number game where I would like to enhance the game a little more by adding when the user is getting warmer, or colder or if they are freezing or boiling... I have no idea how to do this. I have the game to where it is telling you that the user needs to go higher or lower. Can someone please help me??

And also I want a text box to be able to tell how many guesses they have guessed... how do you do that?

Thanks a million!! :)
Public Class frmproject5
    Inherits System.Windows.Forms.Form
    Dim intNumberToGuess As Long
    Dim Count As Integer
    Dim Index As Integer
    Dim previousGuesses As New System.Collections.Hashtable
 
    Private Sub Button1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnguess.Click
 
        Dim intGuess As Long
 
        Dim UpperBound As Long
 
        Dim LowerBound As Long
 
        'check the number being entered into the textbox against the random number set
 
        If IsNumeric(txtguess.Text) Then
 
            intGuess = CLng(txtguess.Text)
 
        Else
 
            ' If no text enetered and button cliked, display message
 
            MsgBox("Enter a number into the textbox!")
 
        End If
 
        ' If the number being enetered is lower than the random number,
 
        Update()
 
        If Not (previousGuesses(intGuess) Is Nothing) Then
 
            lblinfo.Text() = "You've already tried this number - try again"
 
            MsgBox("You've already tried this number - try again")
 
        Else
 
            If intGuess < intNumberToGuess Then
 
                lblinfo.Text() = "Too Low!"
 
                MsgBox("Number is Too Low - Have another go!")
 
 
            ElseIf intGuess > intNumberToGuess Then
 
                lblinfo.Text = "Too High!"
 
                MsgBox("Number is Too High - Have another go!")
 
            ElseIf intGuess = intNumberToGuess Then
 
                lblinfo.Text = "You've Got It!"
 
                MsgBox("Well Done - You've worked out the random number - Now have another go!")
 
                intNumberToGuess = Int((UpperBound - LowerBound + 100) * Rnd() + LowerBound)
 
            End If
 
            'Add the numbers guessed into the listbox
 
            listguess.Items.Add(txtguess.Text)
 
            previousGuesses(intGuess) = intGuess
 
        End If
 
 
 
 
    End Sub
 
    Private Sub btnhowtoplay_enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhowtoplay.Click
        MsgBox("Type a number between 0 and 100 into the box labeled Type Guess Here. The program will generate a random number and will tell you if you've gone to high or to low, keep guessing until you are CORRECT!")
    End Sub
    Private Sub Btnreset_enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnreset.Click
        listguess.Items.Clear()
        txtguess.Text = ""
        listguess.Text = ""
        lblinfo.Text = ""
        btnguess.Enabled = True
        Randomize()
    End Sub
 
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim intNumberToGuess As Long
        Dim UpperBound As Long
        Dim LowerBound As Long
 
        Randomize()
 
        intNumberToGuess = Int((UpperBound - LowerBound + 100) * Rnd() + LowerBound)
    End Sub
End Class

Open in new window

0
Comment
Question by:ashblynn02
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 20

Expert Comment

by:hes
ID: 20412758
How about something like
           If intGuess < intNumberToGuess Then
 
                lblinfo.Text() = "Too Low!"
 	  If Abs(intGuess - intNumberToGuess) > 10 Then
               	 MsgBox("Number is Too Low,  And you are cold- Have another go!")
	  Else
		 MsgBox("Number is Too Low,  But you are getting Warmer- Have another go!")
 	  End If
 
            ElseIf intGuess > intNumberToGuess Then
 
                lblinfo.Text = "Too High!"
 
 	  If Abs(intGuess - intNumberToGuess) > 10 Then
               	 MsgBox("Number is Too High,  And you are cold- Have another go!")
	  Else
		 MsgBox("Number is Too High,  But you are getting Warmer- Have another go!")
 	  End If

Open in new window

0
 

Author Comment

by:ashblynn02
ID: 20416297
Abs is coming up with an  error... it says expressions is not an array or method and cannot have an arguement list...
do you know why it could be doing this?

Thanks!
0
 
LVL 20

Expert Comment

by:hes
ID: 20416361
Is this VB6 ?
Abs is a built in function for absolute value
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 20

Accepted Solution

by:
hes earned 2000 total points
ID: 20416365
Description
Returns the absolute value of a number.
Syntax
Abs(number)
The number argument can be any valid numeric expression. If number contains Null, Null is returned; if it is an uninitialized variable, zero is returned.

Remarks
The absolute value of a number is its unsigned magnitude. For example, Abs(-1) and Abs(1) both return 1.
The following example uses the Abs function to compute the absolute value of a number:

Dim MyNumber
MyNumber = Abs(50.3)  'Returns 50.3
MyNumber = Abs(-50.3) 'Returns 50.3

0
 

Author Comment

by:ashblynn02
ID: 20416439
visual basic express edition 2005... im not too sure if vb6... I am sorry I am new at this...
0
 
LVL 20

Expert Comment

by:hes
ID: 20421820
Try Math.Abs instead of Abs
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question