chris8899 Posted September 11, 2015 Share Posted September 11, 2015 hopefully I have put this in the correct place , and a warm welcome to all the experts here at W3schools!!! being a newbie to visual basic, i have experimented in making a program which i called thunderball random generator. and successfully created it and it works fine, but there is a minor problem, as occasionally it throws up 2 numbers the same in my text boxes i have. my setup is a generate button, with 6 text boxes to show the generated numbers the code i have which obviously must be correct is Private Sub Button1_Click (ByVal sender As Object, BYVal e As EventArgs( Handles Button1.Click Dim RandX As New Random TextBox1.Text = RandX.Next(1, 40) TextBox2.Text = RandX.Next(1, 40) TextBox3.Text = RandX.Next(1, 40) TextBox4.Text = RandX.Next(1, 40) Textbox5.Text = RandX.Next(1, 40) TextBox6.Text = RandX.Next(1, 14) so i am hoping someone can put me right on any coding to add so that it does away with 2 numbers the same appearing . thank you to any help or advice Link to comment Share on other sites More sharing options...
justsomeguy Posted September 11, 2015 Share Posted September 11, 2015 You'll need to use an array to keep a list of the numbers you've already generated, and if a new number is in that list then generate another one. 1 Link to comment Share on other sites More sharing options...
chris8899 Posted September 11, 2015 Author Share Posted September 11, 2015 thank you justsomeguy for your information , will have to take a look at arrays Link to comment Share on other sites More sharing options...
davej Posted September 11, 2015 Share Posted September 11, 2015 One clean approach would be to create a class so that you can do this... Dim RandX As New RandomSetTextBox1.Text = RandX.Get(1)TextBox2.Text = RandX.Get(2)TextBox3.Text = RandX.Get(3)TextBox4.Text = RandX.Get(4)Textbox5.Text = RandX.Get(5)TextBox6.Text = RandX.Get(6) https://msdn.microsoft.com/en-us/library/527aztek.aspx 1 Link to comment Share on other sites More sharing options...
chris8899 Posted September 12, 2015 Author Share Posted September 12, 2015 hi davej thank you for your reply and much appreciated and being new to all this, could you please advise me on how to do this?? although I know its best to learn myself, but at the moment have not got much clue on where to start , so advice would be welcome. thank you Link to comment Share on other sites More sharing options...
davej Posted September 13, 2015 Share Posted September 13, 2015 You should search online for Visual Basic tutorials. Link to comment Share on other sites More sharing options...
chris8899 Posted September 14, 2015 Author Share Posted September 14, 2015 You should search online for Visual Basic tutorials. now thats what a lot of the experts say?? so in reality this forum is not here for helping users much!! i know its best to learn by oneself, so i guess it would be better to do that!! well thanks for at least replying even if it was a ( i don't want to help you , find out yourself ) answer cheers Link to comment Share on other sites More sharing options...
davej Posted September 14, 2015 Share Posted September 14, 2015 I'm not going to generate a tutorial for you from scratch when they already exist. You should come here to the forum with questions when you don't understand something in the tutorials. Link to comment Share on other sites More sharing options...
chris8899 Posted September 14, 2015 Author Share Posted September 14, 2015 (edited) I'm not going to generate a tutorial for you from scratch when they already exist. i do not expect you to ?? You should come here to the forum with questions when you don't understand something in the tutorials and thats what i thought my initial post was to ask for help if i do not understand anything about this?? i joined the forum to get help and guidance on coding etc, and i know you guys are experts on this sort of thing, but did expect little more advice in your answers. but its o.k davej,, i will swat up visual basic and hopefully conquer it by learning oneself. and won't bother any of you experts on any more questions which don't get much of an answer anyway. cheers Edited September 14, 2015 by chris8899 Link to comment Share on other sites More sharing options...
davej Posted September 14, 2015 Share Posted September 14, 2015 Go to the tutorials. Look up how to create and use arrays. Look up how to create and use classes. Look up Random. Look up for and do-while loops. Put those pieces together. If it still doesn't work then come back here. Link to comment Share on other sites More sharing options...
chris8899 Posted September 14, 2015 Author Share Posted September 14, 2015 thank you davej will do as you said and see if I can get somewhere on this Link to comment Share on other sites More sharing options...
chris8899 Posted September 22, 2015 Author Share Posted September 22, 2015 after taking your advice davej, and having a good read up etc on what you suggested, have successfully built a lottery generator without repeating numbers. so thanks for your advice Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now