Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 29th, 2007, 2:30 PM   #1
boatn19
Newbie
 
Join Date: May 2005
Location: Charleston, SC
Posts: 11
Rep Power: 0 boatn19 is on a distinguished road
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
        Dim subscript As Integer
        Dim searchSubscript As Integer
        Dim isFound As Boolean
        Dim raNumber As Integer
        Dim randomGenerator As New Random

        number(0) = 5
        subscript = number(1)
        Do While subscript < number.Length
            raNumber = randomGenerator.Next(1, 54)
            searchSubscript = 0
            Do While searchSubscript < subscript
                isFound = False
                If searchSubscript = raNumber Then
                    isFound = True
                Else
                    searchSubscript = searchSubscript + 1
                End If
            Loop
            If isFound = False Then
                subscript = raNumber
                subscript = subscript + 1
            End If
        Loop
        'display the numbers
        Me.xLotteryLabel.Text = (subscript.ToString())
    End Sub
End Class
boatn19 is offline   Reply With Quote
Old Jul 10th, 2007, 6:53 PM   #2
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 317
Rep Power: 4 mackenga is on a distinguished road
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 Integer
Dim intNumber(5) As Integer
Dim intNew As Integer
Dim rndGen As New Random

For I = 0 To 5
    intNew = rndGen.Next(1, 54)
    For J = 0 To I - 1
        If intNumber(J) = intNew Then
            I = I - 1
            Exit For
        End If
    Next J
Next I

For I = 0 To 5
    lblResult.Caption = lblResult.Caption & intNumber(I)
Next

Notice 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!
__________________
"I'm not a genius. Why do I have to suffer?"
mackenga is offline   Reply With Quote
Old Aug 3rd, 2007, 1:21 PM   #3
zaracyn
Newbie
 
zaracyn's Avatar
 
Join Date: Jun 2006
Location: Michigan
Posts: 13
Rep Power: 0 zaracyn is on a distinguished road
Smile

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!
zaracyn is offline   Reply With Quote
Old Sep 3rd, 2007, 10:47 PM   #4
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 272
Rep Power: 2 Jabo is on a distinguished road
Quote:
Originally Posted by boatn19 View Post
number(0) = 5
subscript = number(1)
This looks to me like a data error.
number(0) is initialized to value 5, number(1) will be initialized to 0, unless that's what you were counting on.
Jabo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
c-unix-childprocesses-random number programmingnoob C 7 Feb 6th, 2007 8:39 PM
Unix commands compatible with Windows? titaniumdecoy Bash / Shell Scripting 7 Oct 5th, 2006 7:25 AM
Jython Jessehk Coder's Corner Lounge 2 Feb 5th, 2006 4:35 AM
[tutorial] Python for programming beginners coldDeath Python 30 Dec 14th, 2005 11:35 AM
FiveDigit + RandomeNumber Game. TecBrain Java 0 Nov 18th, 2005 2:53 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:46 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC