Generates A Random Number And Validates The Users Guess To See If Its Correct?

Jul 31, 2010

I've created code that generates a random number and validates the users guess to see if its correct. I think the code is good but i'm not 100% sure. I need to add additional pieces to the code and i'm not sure where or how to do it. allow the user 10 guesses. after 10 guesses disable the ability to make more guesses if the 10th guess is wrong count each guess entered & display the count as it increments display each guess along with its returned messaeg into a list box. when the user gets correct answer provide a box to allow them to play again. Re-initialize variables back to their starting status.

a. If the user correctly guesses the number in less than 5 guesses display "Either you know the secret or you got lucky!" in a message box. b. If the user correctly guesses the number in 5, 6, or 7 guesses, display "Ah Ha! Do you know the secret?" in a message box. c. If the number of guesses is 8 to 10, then display "Try to do better next time." d. If the number of guesses exceeds 10, then display "You have taken too many guesses."

[Code]...

View 3 Replies


ADVERTISEMENT

Computer Generates A Random Number Then Checks It Against Users

Feb 15, 2011

I'm Trying to make a piece of software where You enter a number and the computer measures the length of the number, and then generates random numbers to match the human number. It will then count the number of guesses and the time taken. However it always comes up that there was a infinite loop "An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll". I have searched up how to do this and I can't seem to find out how. I think I just put my wording wrong when looking it up. My Software Has Has 2 TextBox, 2 Buttons, 6 labels (4 just to make it user friendly) and a timer.

Here is the Code:

Public Class Form1
Dim TimeTaken As Integer
Dim GuessesTaken As Integer

[Code].....

View 9 Replies

Number Guessing Game - Allows A User 10 Attempts To Guess A Random Number Between 1 And 50

Nov 9, 2009

I am attempting to create a game in Visual Studio 2008 that allows a user 10 attempts to guess a random number between 1 and 50. I have a label box in which I would like to display the remaining guesses as they decrement. The code so far appears below.

My two (I am sure very basic) questions are:

1. How would I pass the random integer generated through the Generate Integer function to the AmIRight button's click function? I was trying to decrement the counter each time the "Am I Right " button is pressed.

2. I would also like to evaluate each "guess" when the "Am I right button is pressed. Is it possible to nest a Select Case statement in a For Next Loop?

vb.net Option Explicit OnOption Strict OnOption Infer Off Public Class frmMain Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click Me.Close() End Sub Private Sub txtGuess_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles

[CODE]...

View 3 Replies

Make An App Where Computer Generates A Random Number Using A Function?

Nov 25, 2010

I'm supposed to make an app where computer generates a random number using a function and then the user has to guess the number. If they get it right, they see a picture.... If they get it wrong the loop keeps going until ten guesses are up.. I'm running into quite a few problems...

1. I don't know how to tell if the photo will show up if the number is right because right now I have it set to false in the form, so it dosen't show up but in my loop I included the code that SHOULD allow it to show up if both numbers are the same.... Not sure if this is correct...

2. I have a textbox that is supposed to keep track of the number of guesses but the message automatically becomes Game Over and the guesses go up to 11 as soon as I click the Are You Right Button?

3. When I try to debug, my app freezes and I don't know why...

[Code]...

View 4 Replies

Random Number Generator Generates Same Numbers 19 Times Out Of 20 ?

Apr 1, 2010

I am trying to write a random number function that can just be called from my main module to generate different random numbers. I have tried this several different ways and I am having odd results. Approximately 19 times out of 20 the numbers come back exactly the same, but approximately 1 in 20 they come back as two different numbers. Im using Visual Basic Studio 2008. Here is the code I have so far, or rather, the current version of my many tests I have been running to try and figure it out. Sometimes it takes many runs of the program before the two seperate numbers apear.I've been researching it and have come up with nothing so far.I know I could put them in the module section as two different randoms and it works, but I get extra points if i use a couple classes in my program.This is the main module.

Module Module1
Sub Main()
Dim randomNumOne As New RandNum[code]...........

View 4 Replies

VS 2005 - Correct Messageboxes And Correctly Validates All Through Database?

Jan 9, 2010

I have a login form. all my code is valid with the database and all that.i use an if statement, like if passoword and username match database password and user name then it allows them in then opens my main form. code for that is as follows

[code]...

for some reason, it shows the correct messageboxes and correctly validates all through database, but it closes the Login form correctly, but then shows the main form only for a second, then closes program. I am having issues with similar form opening and closing in other parts of the project as well.

View 12 Replies

Randomizing Program - Making A Program Which Generates A Random Number Between 1 And 10

Oct 20, 2011

I am making a program which generates a random number between 1 and 10 and when 7 appears it is suppose to tell you how many tries it took to get the number 7 and then end the application. This is the code I have used:

CODE:

This code only generates the number 7 and exits the application, each time i click the random button but i want it to show the other number it randomizes too for example 1 2 3 4 .. etc, if u dont understand, please try it, but im trying to say, when i clikc random it just says number 7 (does randomizing in background) and tells you how much tries it took but i want it to show the other number it randomized also and when 7 appears, then exit the program

View 2 Replies

VS 2005 Getting The Correct Number Of Attributes To Match The Correct Number Of Text Boxes?

Apr 18, 2009

I have created a basic query generator which allows a user to select the Select, WHERE and criteria attributes using a number of checkboxes.However i have got stuck. In the results form i have the following code

Private Sub DisplayRecord()
RichTextBox1.Text = ds.Tables("newResults").Rows(intCurrentRecord).Item(0)
RichTextBox2.Text = ds.Tables("newResults").Rows(intCurrentRecord).Item(1)
RichTextBox3.Text = ds.Tables("newResults").Rows(intCurrentRecord).Item(2)

[code]....

The program keeps on crashing if the user does not select the corresponding amount of display records from above for the amount of attributes they want for the SELECT part of the query in the intreface in form 1.

How would i go about making something where the number of SELECT attributes selected which are listed in a string create the correct number of textbox fields in the results form (form2)

View 1 Replies

Guess The Number Game - Background Color

Sep 21, 2009

I need to make a "Guess The Number Game." It needs to choose a random number between 1 to 1000. I need to change the color of the background to red if the number guessed gets closer to the correct answer. And if you are farther away the background color changes to blue. Basically hot if you are close and cold if you are far away. I also need to know what the default color of the background is so that when I press the start game or if I get the number correct the background color changes back to the default color. I though that the default color was WhiteSmoke but it is off a little bit.

Also, if I get the correct number the text box needs to be disabled. Then, when I press the start game button the text box needs to be enabled. I can't get the Hot and Cold part to work. I was just going to use something like if the number was either 50 off of the random number the background color would turn red. All other number would make it turn blue. Then when the correct number is entered the background color would change to Green.

Below is the code that I have.
Public Class Form1
Dim randomGenerator As New Random
Dim number As Integer
Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
[Code] .....

View 3 Replies

This Random Only Generates One Value?

Mar 11, 2010

This code should get one random line from sample.txt and put it in Label1 - problem is that it's only getting line 2. Every single time.

Dim ioLine As String ' Going to hold one line at a time
Dim ioLines As String ' Going to hold whole file
Dim ioFile As New StreamReader("sample.txt")

[code]....

View 1 Replies

Make A "guess The Musical Interval" Game - Playing It With Random Numbers?

Apr 30, 2009

I'm trying to make a "guess the musical interval" game, which will play two separate random audio files in succession.So far, I've got it doing that quite well. Here's my issue:I have a list of check-boxes listing off the different intervals that I want potentially hear when I click btnPlay. i.e., if every musical interval's checkbox is checked, I want it to potentially play any interval (unison - octave). Easy.However, if I uncheck "unison" I want my random number x to be not equal to my random number y (x <> y)If I uncheck minor 2nd, I want random number x and random number y to never be 1 number apart (x - y <> 1)?

Here's my code, I'm sort of getting lost here. I can't get inequalities to work, it says "expression is not a method."

Public Class Form1
Dim x As Integer
Dim y As Integer

[code]....

View 2 Replies

Generates A Random Password And Store The Value To A Label

Apr 18, 2012

I have the following code which extracts the contactcode from a table in a database;

[Code]...

Code: lblUniqueID.Value() = (RandomPassword.Generate(4, 6)) Now, I want to compare the contactcode values extracted from the database and the value stored in lblUniqueID.Value(). If the random password is similar to one of the contactcode then generate another RandomPassword IF NOT then place the value to another label called lbltransfer.text.

I'll insert that value to the database.. The idea is extract all the contactcodes(these are the random passwords already generated and stored) from the database. Compare with the new generated password if it exists then create another one if not then store it in a label called lbltransfer.text.

View 3 Replies

Vb 2008 Number Guess Game - Operator '<' Is Not Defined For Types 'System.Windows.Forms.Button' And 'Integer'

Oct 29, 2011

I am getting Errors: Operator '<' is not defined for types 'System.Windows.Forms.Button' and 'Integer'.

Operator '>' is not defined for types 'System.Windows.Forms.Button' and 'Integer'.
Value of type 'Integer' cannot be converted to 'System.Windows.Forms.Button'.

And my program does not work!

Below is my code..............

Private Sub ProgressBar1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgressBar1.Click
ProgressBar1.Value = TextBox1.Text
End Sub

[CODE]...

View 11 Replies

Generates A Number 1-13 BUT Doesn't Ever Generate A Certain Number

Nov 29, 2009

Anyway, I'm primarily a web developer so I'm only really fluent in PHP and everything else it entails.For my assignments the examination board suggests Visual Basic, so I'm just needing a little help as I'm not too great at it yet. [code] How could I ensure it generates a number 1-13 BUT doesn't ever generate a certain number, e.g. generate a number 1-13 but NOT 7.

View 4 Replies

Program That Generates A Random Line Of Text From A .txt File

Nov 26, 2009

I got a little program that generates a random line of text from a .txt file and all is working well, at least for the most part.

On occasion I get an error message popup saying "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: Index."

Here's my code:

CODE:

The last bit is where the random number is generated, which I am guessing where the problem itself is, but am unsure as to how to fix it...

View 1 Replies

VS 2008 Button Click Generates 4 Random Numbers

Jul 28, 2009

How can I make a command button, When clicked, Generate 4 random digit numbers? such as 5545 or 7492, Any random 4 digits.

View 13 Replies

Make An Application Where When The User Clicks A Button, It Generates A Series Of 100 Random Numbers Between 1 And 1000

Mar 15, 2011

I'm trying to make an application where when the user clicks a button, it generates a series of 100 random numbers between 1 and 1000, and then saves those numbers in a text file. All I could come up with is generating ONE random number, but I can't figure out how to make it 100. Here is what I have:

[Code]...

View 4 Replies

Write A Program That Validates An Inputted Ten Digit ISBN Number Using The Check-digit?

Sep 16, 2011

I'm supposed to write a program that validates an inputted ten digit ISBN number using the check-digit at the end to ensure that the sum is a multiple of eleven. Before calculating this and detecting if the entered number is indeed a valid ISBN, we're required to check the first nine digits and see if they are indeed integers. After this the tenth digit is checked to see if it is "X" (for ten) or 0-9.

With the code I've written it keeps returning false for whether or not the ISBN is valid, even with valid numbers. I feel like its something to do with the hyphens; have I misused the replace function?I'm a little lost on how to make my code work, but I'm fairly certain my logic is okay so far.

[Code]...

View 4 Replies

VS 2008 Generates Catalog Number For Library?

Mar 3, 2011

generating a catalog number for a library system?It is one of the requirement of the panel in my thesis, though its not fits correctly but atleaast, there is suggestion given in a generated catalog.

View 3 Replies

Verify If The Users (Username + Passowrd) Is Correct?

Jun 26, 2010

Ive googled and found only "GetElementById" which is not what im looking for. Also this is for logging in to a site through a vb .net form only.

I just want it to verify if the users (Username + Passowrd) is correct and telling me some how if its correct or not.

Ive got permission from the respected owner here how the link to connect looks like [URL]

Also i have to do this through "http get request" + "Winsocks" i think.

View 3 Replies

Stop Users From Typing Anything Into The Textbox If The Datatype Isn't Correct?

May 3, 2009

I have a form that allows users to enter information into a few textboxes. When users click save, the information will be transferred into the datagridview.

My problem now is, for instance, there is a textbox called "Price" with the datatype "money" which users are only allowed to enter numbers. If users enter alphabets, errors will occur. I don't wanna use try catch, I would like to try different methods such stopping users from entering anything into the textbox when the datatype isn't correct - nothing will appear in the textbox when users hit all the keys in the keyboard except for numbers.

View 3 Replies

Creating A New Random Generator Each Time Should Reduce The Number Of Random Repetitions?

May 26, 2011

I've read numerous posts and threads about random number generation, but I havent' run across this.If I generate a bunch of random numbers, the results are radically different if I create a new Random generator for each number than if I use on Random generator for all the numbers. The results are much more consistent and evenly distributed if I use the same Random generator.I would have thought the opposite,because creating a new Random generator each time should reduce the number of random repetitions, if a different time slice is used to create the random number.[code]......

View 9 Replies

Program That Generates Random Numbers For A "Lottery"

Oct 15, 2011

Making a program that generates random numbers for a "Lottery" (really for homework). Four different types of games and must show up on the GUI when click generate. My question is do you have to have different dim randomObject As New Random() for every Sub to produce different numbers? Every single type of game has different range of number. The Sub needs to return the results back as a string. If I request the method each time will I get a different number back from the range? Here is what I have but just so lost.

Public Class LotteryNumberGenerator
Dim randomObject As New Random()
Private Sub genButton_Click(ByVal sender As System.Object, ByVal e As

[Code].....

View 1 Replies

Code Generate A Random Number / How To Make It 'TRULY' Random

May 29, 2011

I am trying to make a texas hold em game and it is of the utmost importance that my code generate a random number. But using a random number function that I always end up with a lot of the same numbers over and over again. Any ideas on how to make it "TRULY" random? [code]

View 3 Replies

VS 2010 - Image Viewer - Random Number Is Not That Random At All

Apr 19, 2012

I've made an image viewer which opens a random image from a specified folder, but the random number is not that random at all... I've already used Randomize(), but without result.

View 3 Replies

ATM System - Check Card Number Matches Up To The Users PIN Number

Mar 13, 2009

I am trying to make a basic ATM system, iv got all the interface done and I have made the link to my SQL database etc. the part i'm stuck on is how I can run a check to see if a bank card number matches up to the users PIN number. To simulate the user putting a card into the machine I've used a combo box, and that lists all the cards, that haven't been flagged as confiscated (there's a column in my ATMCards table that I can set to true or false) then after the user has selected a relevant card there's another text box where they can enter in their PIN number.

Now what I want to do is, if they chose the card number 1234567890123456 in the combo box and they enter in the PIN 1234 into the text box, then, after clicking the check PIN Button if the pin is correct they need to be taken to another from where they can check their balance etc., and if its wrong they got three attempts after which point i want to flag that card as confiscated.

View 4 Replies

Game Getting Random Strings - No Correct Results

Jun 22, 2010

When I use my own word e.g. here "jose" the results are correct but when I use random string it doesnt work the same.

Here's my code
Imports System.Text
Public Class Form2
Dim guess As String = " "
Dim bulls As Integer = 0
Dim cows As Integer = 0
[Code] .....

View 1 Replies

Check If Input To Group Number And Number Of Units Are Correct Input By Making Error Handling Exceptions

Sep 23, 2010

Part of my assignment is to check if input to Group Number and Number of Units are correct input by making error handling exceptions...

I have to check the following:
a) group number is neither 501 nor 062
b) number of units are NOT numbers
c) number of units is NOT a positive number

So my first question is, am I checking correctly? 2nd question is, How do I make sure my Exceptions will pertain to their correct respective things (a, b, and c.. above)?

[Code]...

View 6 Replies

Create A Random Number Generator That Iterates Through A Series Of Number Between An Upper And Lower Bound?

Jun 24, 2010

i wanted to create a random number generator that iterates through a series of number between an upper and lower bound. say between 1 and 100. Basically I want the number generator to pick the numbers randomly and then display them until all 100 numbers are picked without any duplicates. so thats easy I can code that. But what I don't know is how to show those numbers in the order they are generated on a windows form. So i have basically a variable that I will let be changed 100 times (or however many times I want, I don't want their to be a size constraint just using 100 as an example) and each time the number is generated I want it displayed on screen (in a list or something not sure what. Hopefully some type of scrollable list) and each successive number also to be displayed in same format beneath it so that I can see the list in its entirety. What type of form control do i use for that? I could do messagebox.show for each iteration but then user is required to hit ok after each iteration and that would obviously be a bad idea if user selected a large number to work through. Anyways, code isn't exactly necessary just point me in the right direction, i.e.what control (if any) to use.how to format the change in data?

View 7 Replies

Random Number Lotto Match With User Number Picks?

Nov 4, 2008

I am trying to create a lotto simulation, but don't know how to continue.I am using numericupdowns to allow users to select 6 lotto numbers. and labels to display what they have chosen, but i'm not sure how to prevent duplicates without creating a large number of If statementsMy question is, is there an easier way to prevent duplicates without writing a bunch of if statements?here is my code:

Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Lotto1, Lotto2, Lotto3, Lotto4, Lotto5, Lotto6 As Single Lotto1 = Val(NumericUpDown1.Text) lblLotto1.Text = Lotto1 Lotto2 = Val(NumericUpDown2.Text) lblLotto2.Text = Lotto2 Lotto3 = Val(NumericUpDown3.Text)

[code]....

I don't understand how to save the user selected numbers, let the computer generate 6 random numbers, and match the two sets of numbers together to see how many matches there are. As far as I understand the numbers should be stored in 2 separate arrays and then matched together to find any matches.

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved