Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Vb Lotto Program


  • Please log in to reply
7 replies to this topic

#1 geekman2000

geekman2000

  • Members
  • 10 posts
  • OFFLINE
  •  
  • Local time:08:20 AM

Posted 07 June 2007 - 07:36 AM

Hiya i have to write a VB program which generates six lotto numbers, and a bonus ball, and then sort into asscending order and print on to labels. i have got it to generate six numbers and print on to the labels, but i can't get it to generate a bonus ball, or sort them and print them on to the labels underneath.

Here is the code i have allready:

Private Sub cmdchoose_Click()
' Array
Dim arrNumber(1 To 6) As Integer
' Random Number
Dim intLucky As Integer
' Selection Counter
Dim intCount As Integer
' Previous Selection Counter
Dim intCheck As Integer

' Select Six Numbers
For intCount = 1 To 6
' Start Program
Start:
' Start Number Generater
Randomize (Timer)
' Generate number from 1 to 49
intLucky = Int((49 * Rnd) + 1)
For intCheck = 1 To 6
If intLucky = arrNumber(intCheck) Then
'If selected number already present, select again
GoTo Start
End If
Next intCheck
' Store selected number in array
arrNumber(intCount) = intLucky
' apply generated number to labels
lblball1(intCount - 1) = arrNumber(intCount)
Next intCount

End Sub

Private Sub cmdquit_Click()
End
End Sub

Private Sub Form_Load()
Dim i As Integer
For i = 0 To 5
lblball1(i).Caption = ""
Next i
End Sub

i need to add to the code, to make it generate a bonus number and sort into asscending.

if anyone can help thanks

BC AdBot (Login to Remove)

 


#2 Keithuk

Keithuk

  • Members
  • 960 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:02:20 PM

Posted 07 June 2007 - 05:36 PM

You need to use a Bubble Sort, do a search on VBforums :thumbsup:

Edited by Keithuk, 07 June 2007 - 05:41 PM.

Keith

Windows ME (spare computer)
Windows XP 2002 Professional SP3 (desktop computer)
Windows 7 Professional SP1 32bit (laptop computer)

Windows 8 64bit spare drive for laptop computer


#3 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:07:20 AM

Posted 07 June 2007 - 09:20 PM

IMHO, for only six numbers, any sorting algorithm will do. Or sorting on insertion.

At any rate, we would be glad to help with any problems you may be having, but we will not write the code for you. Show us your sorting algorithm, and we will be glad to help you sort it out. (pun intended)

#4 geekman2000

geekman2000
  • Topic Starter

  • Members
  • 10 posts
  • OFFLINE
  •  
  • Local time:08:20 AM

Posted 08 June 2007 - 03:29 AM

Hiya, i just need to know how to alter the code, to get it to generate a bonus number and print it on the label, for the bonus number.

this is the code that generates the numbers which happens when you click choose number:

' Select Six Numbers
For intCount = 1 To 6
' Start Program
Start:
' Start Number Generater
Randomize (Timer)
' Generate number from 1 to 49
intLucky = Int((49 * Rnd) + 1)
For intCheck = 1 To 6
If intLucky = arrNumber(intCheck) Then
'If selected number already present, select again
GoTo Start
End If
Next intCheck
' Store selected number in array
arrNumber(intCount) = intLucky
' apply generated number to labels
lblball1(intCount - 1) = arrNumber(intCount)
Next intCount

And this code, applys it to the labels:

Private Sub Form_Load()
Dim i As Integer
For i = 0 To 5
lblball1(i).Caption = ""
Next i
End Sub

Could you please help me adjust it, so it will generate the bonus ball as well.
I would also appreciate it, if some one could help with sorting the numbers into asscending.

Thanks

Edited by geekman2000, 08 June 2007 - 03:30 AM.


#5 Keithuk

Keithuk

  • Members
  • 960 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:02:20 PM

Posted 08 June 2007 - 06:35 AM

Dim arrNumber(1 To 6) As Integer

Well your array is 1 to 6 which will give you 6 numbers. Either make it 0 to 6 or 1 to 7 then the extra number can be your bonus. :thumbsup:

Keith

Windows ME (spare computer)
Windows XP 2002 Professional SP3 (desktop computer)
Windows 7 Professional SP1 32bit (laptop computer)

Windows 8 64bit spare drive for laptop computer


#6 geekman2000

geekman2000
  • Topic Starter

  • Members
  • 10 posts
  • OFFLINE
  •  
  • Local time:08:20 AM

Posted 08 June 2007 - 05:53 PM

How would i go about sorting them now that i have a bonus ball to appear?

#7 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:07:20 AM

Posted 08 June 2007 - 06:00 PM

Read the link that KeithUK gave you.

#8 geekman2000

geekman2000
  • Topic Starter

  • Members
  • 10 posts
  • OFFLINE
  •  
  • Local time:08:20 AM

Posted 09 June 2007 - 07:24 AM

yeah, i used the link.but i couldn't find anything about sorting so i was wondering could you please help me. i have added a button, which when clicked, is supposed to sort the numbers,but i was wondering what code do i use to sort.

Edited by geekman2000, 09 June 2007 - 07:26 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users