SunQuest
           Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old April 18th, 2008, 10:43 AM
shotgunjoe shotgunjoe is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 4 shotgunjoe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 41 sec
Reputation Power: 0
Sorry... Yet Another Question... (See Edit)

Hey there, I'm new to this forum and VB programming, so sorry if this seems like a noobish question.

Basically for a school project I have to create a lottery program which generates six random numbers, then performs a bubble sort to sort these numbers into order and then display them in a picture box. I've been struggling with this for days, I have no idea but my code looks OK to me, and whenever I click the command button which is associated with this code I always get an error message saying "Wrong Number Of Arguments Or Invalid Property Assignment" and always highlights the first "Populate_List list()" part.

Here's the code:

Option Explicit
Dim Counter As Integer
Dim list(6) As Variant

Private Sub CmdStart_Click()
'Generates six random numbers between one and forty eight and performs a bubble
'sort on them.
Randomize
Populate_List list() (this part is always highlighted when I try to click CmdStart)
Bubble_Sort list()
Output_Results
End Sub

Private Sub Populate_List()
Dim Fill As Integer
For Fill = 0 To 6
list(Fill) = Int(48 * Rnd) + 1
Next Fill
End Sub

Private Sub Bubble_Sort()
Dim Outer As Integer
Dim Inner As Integer
For Outer = 6 To 0 Step -1
For Inner = 0 To Outer - 1
If list(Inner) > list(Inner + 1) Then
Temp = list(Inner)
list(Inner) = list(Inner + 1)
list(Inner + 1) = Temp
End If
Next Inner
Next Outer
End Sub

Private Sub Output_Results()
Dim Count As Integer
PicResult.Print " ";
For Count = 0 To 15
PicNumbersOne.Print list(Count);
Next Count
End Sub

Any help you could give me would be much appreciated.


EDIT: This problem has been solved, but now I have another.

OK, so after the random numbers have been generated, the user then enters six numbers between one and fifty, which are also displayed in a picture box. This is fine, and these numbers are stored in the array yournumbers. However, the problems start when the user clicks the CmdCheck Button, which is for the user to check their "winnings". The basis of this part was that the two arrays (one for the random numbers and one for the user entered numbers) are compared using a binary search and if a number the user entered matches one of the randomly generated numbers then a value of one will be added to a variable called "Winnings", and once all of the numbers have been compared then the final value of Winnings would be used in a Select...Case statement to determine how much the user would win. However, I seem to have hit a bit of a snag, as when I click the command button to start this a message box comes up saying "Next Without For". I have no idea why this is, as I have entered a For, which is bolded, and when I take the Next Count away it says "For Without Next." Again, here is the code:

Private Sub CmdCheck_Click()
Dim Count As Integer, Middle As Integer, Found As Boolean, FirstLocation As Integer, Passes As Integer
Dim LastLocation As Integer, Pointer As Integer, Winnings As Integer, List(6) As Variant, SearchKey As Integer
Winnings = 0
Passes = 0
For Count = 0 To 5
Found = False
Passes = Passes + 1
FirstLocation = 0
LastLocation = 5
SearchKey = yournumbers(Count)
Do
Pointer = (FirstLocation + LastLocation) / 2
If List(Pointer) < SearchKey Then
FirstLocation = Pointer + 1
Else
LastLocation = Pointer - 1
End If
If List(Pointer) = SearchKey Then
Found = True
Winnings = Winnings + 1
End If
Next Count
Loop Until Passes > 4
Select Case Winnings
Case 0
PicWinnings.Print "Sorry, you have not won anything this time."
Case 1
PicWinnings.Print "You have won £10!"
Case 2
PicWinnings.Print "You have won £100!"
Case 3
PicWinnings.Print "You have won £1000!"
Case 4
PicWinnings.Print "You have won £10000!"
Case 5
PicWinnings.Print "You have won £100000!"
Case 6
PicWinnings.Print "You have won the jackpot of £1000000!"
End Select
End Sub

I've bolded the For and Next statements.

I also don't know if a binary search is the best way to go with this, if its not then could anyone suggest any alternatives?

Sorry for what must seem like really stupid questions, I am very much a noob to this stuff.

Again, thanks in advanced for any help you can give. I would ask my teacher but my school's on break and this has to be done for when we go back, plus I figure I've already gotten great help from you guys, so why not just ask again?

Last edited by shotgunjoe : April 18th, 2008 at 02:01 PM. Reason: Question answered, but another question came up.

Reply With Quote
  #2  
Old April 18th, 2008, 10:54 AM
zynder's Avatar
zynder zynder is offline
Not much of a contributor
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2006
Location: Hidden
Posts: 800 zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 140447 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140447 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140447 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140447 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140447 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140447 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Week 2 Days 22 h 6 m 32 sec
Reputation Power: 647
Send a message via Yahoo to zynder
It's because your subs are not accepting parameters.

Populate_List list()

list() seems to be on the wrong place for an argument. What is that anyway?

Reply With Quote
  #3  
Old April 18th, 2008, 10:56 AM
shotgunjoe shotgunjoe is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 4 shotgunjoe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 41 sec
Reputation Power: 0
list() was meant to be an array to accept the random numbers, then I'd just display that "list" in the picture box.

Also, I am a complete noob to this, how would I make the subs accept paramaters?

Thanks for your help!

Reply With Quote
  #4  
Old April 18th, 2008, 11:06 AM
LyonHaert's Avatar
LyonHaert LyonHaert is offline
Arcane Scribbler
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2005
Location: Indianapolis, IN
Posts: 1,593 LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 13 h 14 m 58 sec
Reputation Power: 364
Well, since your list variable is module-level and all the functions have access to it anyway, you could remove 'list()' from the end of the function calls. Instead of calling Populate_List list() you would call Populate_List.

I think that would make it work. However, if you want to change it so that you pass list to each of those, that's a different story.
__________________
Joel B Fant - LyonHaert.net

2 + 2 is... 10... in base 4

Reply With Quote
  #5  
Old April 18th, 2008, 11:48 AM
zynder's Avatar
zynder zynder is offline
Not much of a contributor
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2006
Location: Hidden
Posts: 800 zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 140447 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140447 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140447 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140447 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140447 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140447 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Week 2 Days 22 h 6 m 32 sec
Reputation Power: 647
Send a message via Yahoo to zynder
^ Follow above's advice. Since list() is pulic just call it by its name.

Reply With Quote
  #6  
Old April 18th, 2008, 11:57 AM
shotgunjoe shotgunjoe is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 4 shotgunjoe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 41 sec
Reputation Power: 0
Thanks you so much guys, it now works fine!

Reply With Quote
  #7  
Old April 18th, 2008, 12:04 PM
medialint's Avatar
medialint medialint is offline
spirit duplicator
Click here for more information.
 
Join Date: Apr 2004
Location: \\Firecrate\
Posts: 12,299 medialint User rank is General 23rd Grade (Above 100000 Reputation Level)medialint User rank is General 23rd Grade (Above 100000 Reputation Level)medialint User rank is General 23rd Grade (Above 100000 Reputation Level)medialint User rank is General 23rd Grade (Above 100000 Reputation Level)medialint User rank is General 23rd Grade (Above 100000 Reputation Level)medialint User rank is General 23rd Grade (Above 100000 Reputation Level)medialint User rank is General 23rd Grade (Above 100000 Reputation Level)medialint User rank is General 23rd Grade (Above 100000 Reputation Level)medialint User rank is General 23rd Grade (Above 100000 Reputation Level)medialint User rank is General 23rd Grade (Above 100000 Reputation Level)medialint User rank is General 23rd Grade (Above 100000 Reputation Level)medialint User rank is General 23rd Grade (Above 100000 Reputation Level)medialint User rank is General 23rd Grade (Above 100000 Reputation Level)medialint User rank is General 23rd Grade (Above 100000 Reputation Level)medialint User rank is General 23rd Grade (Above 100000 Reputation Level)medialint User rank is General 23rd Grade (Above 100000 Reputation Level)  Folding Points: 232541 Folding Title: Super Ultimate Folder - Level 1Folding Points: 232541 Folding Title: Super Ultimate Folder - Level 1Folding Points: 232541 Folding Title: Super Ultimate Folder - Level 1Folding Points: 232541 Folding Title: Super Ultimate Folder - Level 1Folding Points: 232541 Folding Title: Super Ultimate Folder - Level 1Folding Points: 232541 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Months 3 Weeks 4 h 43 m 27 sec
Reputation Power: 2547
To actually pass an array

Code:
Private Sub Populate_List(ByRef varList() As Variant)


This is cleaner than using a public array and for a large scale project would be advised.
__________________
medialint.com

"Energy has the opportunity to change the climate if it's done right." - Sen. John Ensign, R-Nev. (quoted out of context)

Reply With Quote
  #8  
Old April 18th, 2008, 02:02 PM
shotgunjoe shotgunjoe is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 4 shotgunjoe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 41 sec
Reputation Power: 0
I've updated my first post with yet another problem I was hoping you guys could help me out with, thanks!

Reply With Quote
  #9  
Old April 18th, 2008, 02:30 PM
LyonHaert's Avatar
LyonHaert LyonHaert is offline
Arcane Scribbler
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2005
Location: Indianapolis, IN
Posts: 1,593 LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 13 h 14 m 58 sec
Reputation Power: 364
Quote:
Originally Posted by shotgunjoe
I've updated my first post with yet another problem I was hoping you guys could help me out with, thanks!
Please don't do it that way. If it is related to the original problem, you can put it all in a new post. If it is completely different, I think the recommendation is to start a new thread (it helps when people are searching the forums for help).

Also, I think now is a good time to remind you to check out the 'Read this first' sticky threads and to use [code][/code] tags to preserve indentation and make your code easier to read.
Comments on this post
zynder agrees!

Reply With Quote
  #10  
Old April 18th, 2008, 02:35 PM
LyonHaert's Avatar
LyonHaert LyonHaert is offline
Arcane Scribbler
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2005
Location: Indianapolis, IN
Posts: 1,593 LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 13 h 14 m 58 sec
Reputation Power: 364
Your new problem is because you have a for-loop and a do-until loop overlapping:
Code:
For Count.....
   Do '?
Next Count
Loop Until.... 'belongs to Do!
They should be separate or one fully nested inside the other.

You can't have the beginning of a control structure inside another control structure and not have the end inside the same scope (and vice versa).

Reply With Quote
  #11  
Old April 18th, 2008, 02:37 PM
zynder's Avatar
zynder zynder is offline
Not much of a contributor
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2006
Location: Hidden
Posts: 800 zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 140447 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140447 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140447 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140447 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140447 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140447 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Week 2 Days 22 h 6 m 32 sec
Reputation Power: 647
Send a message via Yahoo to zynder
Nice catch Lyon.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Wrong Number Of Arguments Or Invalid Property Assignment?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump