![]() |
only displays 1 number not 6
the following code is only displaying one number and I am trying to get it display six numbers
:
Dim number(5) As Integer |
I can see what you're trying to do there, but you're getting confused between numbers, subscripts, etc. You start off by generating numbers into your array, then you display the numbers (right?). So how about:
:
Dim I As Integer, J As IntegerNotice I don't really need the boolean to note whether I've found the number already there; instead, after the new number is generated I search through the array to see if it's already there and take one off I if it is, which will push the outer loop back so it runs this step again next time. Then I Exit For to duck out of the inner For loop to let that happen. This is probably not the best way and isn't exactly what you were asking for but I was finding your code confusing, so I hope you can figure out how to put the two together and that this helps. I also hope it runs - I don't actually have VB handy to try it out! |
You both appear to be forgetting to populate your array, it might look something like this:
Private Sub FindWinningLottoNumberButton_Click() Dim I As Integer Dim lottoNum As Integer Dim lottoNumArray(5) As Integer For I = 0 To 5 lottoNum = Rand(1, 56) lottoNumArray(I) = lottoNum ' place code to check for unique numbers here Next I For I = 0 To 5 TextBox1.Text = TextBox1.Text & lottoNumArray(I) & " " Next I TextBox1.Text = TextBox1.Text & vbNewLine End Sub Hope this helps! |
Quote:
number(0) is initialized to value 5, number(1) will be initialized to 0, unless that's what you were counting on. |
| All times are GMT -5. The time now is 11:24 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC