943,865 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 4039
  • VB.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 4th, 2008
0

Guessing Game

Expand Post »
Hi,

I am very new to visual basic 6.0 and I am trying to create a guessing game in visual basic where the computer generates three numbers and the player tries to guess what they are. I am now starting the basics and I have the GUI sorted out but the code is giving me a bit of problem. When the GUESS button is pressed the computer is supposed to generate a random 3 digit number and they must appear as ***. This is what i have so far and it does not work.

Private Sub cmdGuess_Click()
Me.Text2.Text = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

End Sub

The player must then try to guess the three numbers by using a number pad press a button to see if they have won.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
LottaBajan2 is offline Offline
10 posts
since Oct 2008
Oct 4th, 2008
0

Re: Guessing Game

Did you set upperbound and lowerbound to anything?

vb Syntax (Toggle Plain Text)
  1. Private Sub cmdGuess_Click()
  2. Me.Text2.Text = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
  3.  
  4. End Sub
Reputation Points: 27
Solved Threads: 29
Posting Whiz
timothybard is offline Offline
317 posts
since Mar 2007
Oct 5th, 2008
0

Re: Guessing Game

Please be patient with me as i am a novice at this. No I did not set the upper or lower bounds to anything. Can you explain how to do this?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
LottaBajan2 is offline Offline
10 posts
since Oct 2008
Oct 5th, 2008
0

Re: Guessing Game

Here is some code that will hopefully point you in the direction you are trying to go:

vb Syntax (Toggle Plain Text)
  1. Private Sub cmdGuess_Click()
  2.  
  3. dim upperbound as integer
  4. dim lowerbound as integer
  5.  
  6. upperbound = 100
  7. lowerbound = 10
  8.  
  9. Me.Text2.Text = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
  10.  
  11. End Sub
Reputation Points: 27
Solved Threads: 29
Posting Whiz
timothybard is offline Offline
317 posts
since Mar 2007
Oct 5th, 2008
0

Re: Guessing Game

Thank you it worked somewhat but i have to solve some other problems. Can i get bact to you if more help is needed
Reputation Points: 10
Solved Threads: 0
Newbie Poster
LottaBajan2 is offline Offline
10 posts
since Oct 2008
Oct 5th, 2008
0

Re: Guessing Game

Of course; I'd be happy to help whenever I can!
Reputation Points: 27
Solved Threads: 29
Posting Whiz
timothybard is offline Offline
317 posts
since Mar 2007
Oct 5th, 2008
0

Re: Guessing Game

My numbers are being randomly generated by the computer but when i try to get my player to select 3 numbers one is being replaced by the other (in other words only one number is showing up) i know i need to do an if statement but cannot figure out how to code it. I know it needs to be something like this; if the player choses (for instance) 1 3 5 then store it and compare it to the randomly stored number. so should it be something like this?

if (num = 1) then
lbl.player.caption = 1

elseif (num = 2) then
lbl.player.caption = 2

I am choosing the numbers by a numbered key pad.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
LottaBajan2 is offline Offline
10 posts
since Oct 2008
Oct 5th, 2008
0

Re: Guessing Game

How do I code my keypad?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
LottaBajan2 is offline Offline
10 posts
since Oct 2008
Oct 8th, 2008
0

Re: Guessing Game

Hello,

Nobody seems to be answering my question is that because I really have no clue about what I am doing? I am feeling really pressured here because I really have no clue and i would really like to learn this!!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
LottaBajan2 is offline Offline
10 posts
since Oct 2008
Oct 8th, 2008
0

Re: Guessing Game

Okay... as far as the first issue... you mention that the program picks three random numbers okay but that one is being replaced? It sounds like you are storing a different value in the variable. Do you have any code?

As far as the keypad, what are you trying to do with it? Are you trying to use the keypad to enter numbers in a textbox or are you trying to detect when a user presses one of the buttons on the keypad?
Reputation Points: 27
Solved Threads: 29
Posting Whiz
timothybard is offline Offline
317 posts
since Mar 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: SQL Error Display Event Form
Next Thread in VB.NET Forum Timeline: image processing in vb.net





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC