Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 244,261 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,239 people online right now. Registration is fast and FREE... Join Now!




"Guess the Number" Game in VB

 
Reply to this topicStart new topic

"Guess the Number" Game in VB, I need help before I completely go crazy...

jbates3
30 Nov, 2008 - 07:04 PM
Post #1

New D.I.C Head
*

Joined: 30 Nov, 2008
Posts: 4

I' m having trouble with this assignment for class. It's already a week late , but I'd rather learn how to do it than submit an incorrect assignment. If you have any questions feel free to ask.
Thanks.

CODE


Dim guessNumberTextBox As Integer
        Dim correctNumber As Integer
      

        correctNumber = CInt(Int((100 - 1 + 1) * Rnd() + 1))

        Select Case guessNumberTextBox
            Case CInt(guessNumberTextBox < correctNumber)
                outputLabel.Text = "Higher..."

            Case CInt(guessNumberTextBox > correctNumber)
                outputLabel.Text = "Lower..."

            Case CInt(guessNumberTextBox = correctNumber)
                outputLabel.Text = "Correct"
                newGameButton.Enabled = True

        End Select

        If guessNumberTextBox < correctNumber = True Then
            outputLabel.Text = "Higher..."

        ElseIf guessNumberTextBox > correctNumber = True Then
            outputLabel.Text = "Lower..."
        End If
        If guessNumberTextBox = correctNumber = True Then
            outputLabel.Text = "Correct"

        End If

    End Sub

    Private Sub newGameButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles newGameButton.Click
        guessNumberTextBox.Text = ""
        outputLabel.Text = ""
    End Sub



User is offlineProfile CardPM
+Quote Post


VB Crash
RE: "Guess The Number" Game In VB
30 Nov, 2008 - 07:21 PM
Post #2

D.I.C Head
**

Joined: 28 Nov, 2008
Posts: 130



Thanked: 7 times
My Contributions
Use:

Text1 => GeneratorTextBox
Visible=False

Text2 => GuessTextBox

Generate =>CommandButton for Generating Number
Guess => Button for Guess the Number

vb


Private Sub Generate_Click()
Dim i As Integer
i = Int(100 * Rnd) + 1
Text1.Text = i
End Sub
'----------------------------------------------------
Private Sub Guess_Click()
Dim G, i As Integer
i = Text1.Text
G = Text2.Text

If G > i Then MsgBox "Smaler", vbInformation
If G < i Then MsgBox "Bigger", vbInformation
If G = i Then MsgBox "Corect", vbInformation
End Sub


Vace

This post has been edited by VB Crash: 30 Nov, 2008 - 07:22 PM
User is offlineProfile CardPM
+Quote Post

jbates3
RE: "Guess The Number" Game In VB
30 Nov, 2008 - 08:00 PM
Post #3

New D.I.C Head
*

Joined: 30 Nov, 2008
Posts: 4

VB Crash -

I appreciate the time and effort you spent on that reply....but I'm really a beginner and your post does not make sense to me.
I need this explained in english more than code.

Sorry
User is offlineProfile CardPM
+Quote Post

Fuzz_Bullet
RE: "Guess The Number" Game In VB
30 Nov, 2008 - 08:41 PM
Post #4

New D.I.C Head
*

Joined: 30 Nov, 2008
Posts: 25

Is this Visual Basic 6.0?
User is offlineProfile CardPM
+Quote Post

jbates3
RE: "Guess The Number" Game In VB
30 Nov, 2008 - 09:21 PM
Post #5

New D.I.C Head
*

Joined: 30 Nov, 2008
Posts: 4

It's VB 2005 express edition.
The problem is in a book called simply visual basic 2005.

The problems I'm having is I can't tell if it's my random number generator code or is it the case code or is it the If statements that are jacked up!


User is offlineProfile CardPM
+Quote Post

thava
RE: "Guess The Number" Game In VB
1 Dec, 2008 - 03:52 AM
Post #6

D.I.C Addict
Group Icon

Joined: 17 Apr, 2007
Posts: 670



Thanked: 35 times
Dream Kudos: 75
My Contributions
hi there

follow this link
http://msdn.microsoft.com/en-us/library/cy37t14y(VS.80).aspx

now hopefully you under stand the concept the thing is

the expression should return a list of values for that Values we can written a case statement

vb



Dim guessNumberTextBox As Integer
Dim correctNumber As Integer


correctNumber = CInt(Int((100 - 1 + 1) * Rnd() + 1))

Select Case guessNumberTextBox < correctNumber
Case false
outputLabel.Text = "Higher..."

Case true
outputLabel.Text = "Lower..."

End Select

If guessNumberTextBox = correctNumber = True Then
outputLabel.Text = "Correct"
End If

End Sub

Private Sub newGameButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles newGameButton.Click
guessNumberTextBox.Text = ""
outputLabel.Text = ""
End Sub


i think you know that a logical expression has only the outputs as true or false

what i done is just put the expression in the select statement and
for the possible output i write the case statements

hope you under stand


This post has been edited by thava: 1 Dec, 2008 - 03:56 AM
User is offlineProfile CardPM
+Quote Post

jbates3
RE: "Guess The Number" Game In VB
1 Dec, 2008 - 07:05 AM
Post #7

New D.I.C Head
*

Joined: 30 Nov, 2008
Posts: 4

Thanks Thava!

I wish I had gone to this site for some of the other problems I spent countless hours racking my brain over.

I'm sure to be back...
User is offlineProfile CardPM
+Quote Post

VB Crash
RE: "Guess The Number" Game In VB
1 Dec, 2008 - 07:40 AM
Post #8

D.I.C Head
**

Joined: 28 Nov, 2008
Posts: 130



Thanked: 7 times
My Contributions
Make this is easy way:

vb


Private Sub Guess_Click()
Dim i, g As Integer

i = Int(100 * Rnd) + 1
g = Text1.Text

If g > i Then MsgBox "Smaller", vbExclamation
If g < i Then MsgBox "Bigger", vbExclamation
If g = i Then MsgBox "Correct", vbExclamation
End Sub

Private Sub NewGame_Click()
Text1.Text = ""
End Sub



Vace
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 11:42AM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month