|
-
Mar 2nd, 2008, 01:52 AM
#1
Thread Starter
Junior Member
[RESOLVED] [2005] Working with arrays; Lottery number generator for class
Ok, I have just finished my "Introduction to Visual Basic" course, and overall did pretty good (A's and B's on assignments). However, one of the last assignments threw a wrench into the mix and I wasn't able to finish one of three projects.
Text book is Programming with Microsoft Visual Basic 2005: Third Edition (if that matters) with my book got a CD with Visual Basic 2005 Expess Edition (not Visual Studio 2005 Express, CD lacked any other languages). Chapter 9: Arrays, Lesson A, Excercise number 14:
"In this exercise you create an application that generates and displays six unique random numbers for a lottery game. Each lottery number can range from 1 through 54 only.
A) start VB, open partial program, etc.
B)Open the Display Numbers button's Click event procedure. Code the procedure so that it displays six unique numbers int eh interface. (Hint: Store the numbers in a one-dimensional array.)
C) Save, start application, click the Display numbers button several times. Each time you click the button, six unique random numbers between 1 and 54 (inclusive) should appear in the interface.
D) exit program, close code editor and solution"
So, here is what I have:
Code:
Private Sub xDisplayButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xDisplayButton.Click
' declare array and other variables
Dim lottoNumbers() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, _
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, _
31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, _
45, 46, 47, 48, 49, 50, 51, 52, 53, 54}
Dim lottoNumber As Integer
Dim number As Integer
'Dim rad1 As Integer
' Dim rad2 As Integer
'Dim rad3 As Integer
' Dim rad4 As Integer
'Dim rad5 As Integer
'Dim rad6 As Integer
' randomly select 6 unique random numbers from array
'For Each number In lottoNumbers
*****************
*****************
'Next number
'lottoNumber = number
'lottoNumber = rad1 & "-" & rad2 & "-" & rad3 & "-" & rad4 & "-" & rad5 & "-" & rad6
' display numbers in lottery label box
Me.xLotteryLabel.Text = CStr(lottoNumber)
End Sub
So, above I declared my array containing 1 - 54, I declared a variable named lottoNumber and one called number to get numbers from array and then display in label. Notice the ' in front of some code, these are the areas that I am not sure of (along with lines that contain *'s), and therefore marked them to the side. I tried using random numbers (by declaring ' Dim randomgenerator As New random' then using in code. I got it to work, but I had 0's in my output, and therefore, it wasn't randomizing my array. If I try 'randomize (lottoNumbers)' it gives me an error saying "value of type '1-dimensional array of Integer' cannot be converted to 'Double' "
Anyways, I've tried my best to figure this one out (about 12 hours now) and knowing that I am a beginner (by a long shot) I just couldn't wrap my head around what I needed to do to finish this program. This is all the code I have to mess with (I've wrote all of it, none of this was done when I started) so it should have been simple (not 15 pages long or anything), not to mention I was in Introduction class (not even in Programming in Visual Basic yet).
As far as class goes, I'll pass no problems with an easy B without this program being completed, however, for my own sanity, I want to understand so that I can finish this stupid, simple, and annoying program.
Anyone know what I need to do?
Thank you, and sorry if long post, didn't know how much background was needed.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|