943,762 Members | Top Members by Rank

Ad:
Jun 15th, 2005
0

Argument Not Optional message in VB

Expand Post »
Sorry, I am a beginner at Visual Basic, and have had to create this project as part of a school task. It keeps coming up with "argument not optional" on the calls tp checkcards and determinewinnings. I don't knkow what this means really, and I don't know how to fix it. Can you help??

Here is the code:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Option Explicit
  2.  
  3. Private Sub cmdDraw_Click()
  4. 'subroutine to "draw" the cards
  5.  
  6. Call GenerateCards 'calling the GenerateCards subroutine
  7. Call CheckCards 'calling the CheckCards subroutine
  8. Call DetermineWinnings 'calling the DetermineWinnings subroutine
  9.  
  10. End Sub
  11.  
  12. Private Sub cmdStart_Click()
  13. 'subroutine to activate the program when start is clicked
  14.  
  15. cmdDraw.Enabled = True 'enabling the "Draw" command button
  16.  
  17. Dim intwinnings As Integer 'declaring the intwinnings variable as an integer
  18. intwinnings = 0 'setting intwinnings to 0
  19. lblwinnings.Caption = intwinnings 'making the lblwinnings caption 0
  20.  
  21. Randomize 'Telling the program to generate random numbers
  22.  
  23. End Sub
  24.  
  25. Sub GenerateCards()
  26. 'subroutine to generate the random numbers for the variables
  27.  
  28. Dim intcard1, intcard2, intcard3, intcard4 As Integer 'Declaring the variables as integers
  29.  
  30. intcard1 = Int(Rnd * 4) + 1 'making the intcard1 variable equal to a random number between 1 & 2
  31. intcard2 = Int(Rnd * 4) + 1 'making the intcard2 variable equal to a random number between 1 & 2
  32. intcard3 = Int(Rnd * 4) + 1 'making the intcard3 variable equal to a random number between 1 & 2
  33. intcard4 = Int(Rnd * 4) + 1 'making the intcard4 variable equal to a random number between 1 & 2
  34.  
  35. End Sub
  36.  
  37. Sub CheckCards(intcard1, intcard2, intcard3, intcard4 As Integer)
  38. 'subroutine to display image according to the values of the random numbers generated in the GenerateCards subroutine
  39.  
  40. If intcard1 = 1 Then 'Checking if the intcard1 variable is a 1 and if it is, generating a diamond card
  41. imgcard1.Picture = imgdiamond.Picture
  42. Else
  43. If intcard1 = 2 Then 'Checking if the intcard1 variable is a 2 and if it is, generating a hearts card
  44. imgcard1.Picture = imgheart.Picture
  45. Else
  46. If intcard1 = 3 Then
  47. imgcard1.Picture = imgclub.Picture 'Checking if the intcard1 variable is a 3 and if it is, generating a clubs card
  48. Else
  49. If intcard1 = 4 Then
  50. imgcard1.Picture = imgspade.Picture 'Checking if the intcard1 variable is a 4 and if it is, generating a spades card
  51. End If
  52. End If
  53. End If
  54. End If
  55.  
  56.  
  57. If intcard2 = 1 Then 'Checking if the intcard2 variable is a 1 and if it is, generating a diamonds card
  58. imgcard2.Picture = imgdiamond.Picture
  59. Else
  60. If intcard2 = 2 Then 'Checking if the intcard2 variable is a 2 and if it is, generating a hearts card
  61. imgcard2.Picture = imgheart.Picture
  62. Else
  63. If intcard2 = 3 Then 'Checking if the intcard2 variable is a 3 and if it is, generating a clubs card
  64. imgcard2.Picture = imgclub.Picture
  65. Else
  66. If intcard2 = 4 Then 'Checking if the intcard2 variable is a 4 and if it is, generating a spades card
  67. imgcard2.Picture = imgspade.Picture
  68. End If
  69. End If
  70. End If
  71. End If
  72.  
  73.  
  74. If intcard3 = 1 Then 'Checking if the intcard3 variable is a 1 and if it is, generating a diamonds card
  75. imgcard3.Picture = imgdiamond.Picture
  76. Else
  77. If intcard3 = 2 Then 'Checking if the intcard3 variable is a 2 and if it is, generating a hearts card
  78. imgcard3.Picture = imgheart.Picture
  79. Else
  80. If intcard3 = 3 Then 'Checking if the intcard3 variable is a 3 and if it is, generating a clubs card
  81. imgcard3.Picture = imgclub.Picture
  82. Else
  83. If intcard3 = 4 Then 'Checking if the intcard3 variable is a 4 and if it is, generating a spades card
  84. imgcard3.Picture = imgspade.Picture
  85. End If
  86. End If
  87. End If
  88. End If
  89.  
  90.  
  91. If intcard4 = 1 Then 'Checking if the intcard4 variable is a 1 and if it is, generating a diamonds card
  92. imgcard4.Picture = imgdiamond.Picture
  93. Else
  94. If intcard4 = 2 Then 'Checking if the intcard4 variable is a 2 and if it is, generating a hearts card
  95. imgcard4.Picture = imgheart.Picture
  96. Else
  97. If intcard4 = 3 Then 'Checking if the intcard4 variable is a 3 and if it is, generating a clubs card
  98. imgcard4.Picture = imgclub.Picture
  99. Else
  100. If intcard4 = 4 Then 'Checking if the intcard4 variable is a 4 and if it is, generating a spades card
  101. imgcard4.Picture = imgspade.Picture
  102. End If
  103. End If
  104. End If
  105. End If
  106.  
  107. End Sub
  108.  
  109. Sub DetermineWinnings(intcard1, intcard2, intcard3, intcard4, intwinnings As Integer)
  110. 'subroutine to calculate, and keep tally of the user's winnings
  111.  
  112. If intcard1 = intcard2 = intcard3 = intcard4 Then 'Checking the cards for four of the same
  113. intwinnings = intwinnings + 5 'stating that if a set of four is found, the winner receives $5
  114. lblwinnings.Caption = intwinnings 'Updating the onscreen total
  115. Else
  116. If intcard1 = intcard2 = intcard3 Or intcard2 = intcard3 = intcard4 Or intcard1 = intcard2 = intcard4 Or intcard1 = intcard3 = intcard4 Then 'checking the cards for triplets
  117. intwinnings = intwinnings + 3 'stating that if a triplet is found, the winner receives $3
  118. lblwinnings.Caption = intwinnings 'updating the onscreen total
  119. Else
  120. If intcard1 = intcard2 Then 'checking the cards for pairs
  121. intwinnings = intwinnings + 1 'stating the if a double is found, the winner receives $1 for each pair
  122. lblwinnings.Caption = intwinnings 'updating the onscreen total
  123. End If
  124.  
  125.  
  126. If intcard2 = intcard3 Then 'checking the cards for pairs
  127. intwinnings = intwinnings + 1 'stating the if a double is found, the winner receives $1 for each pair
  128. lblwinnings.Caption = intwinnings 'updating the onscreen total
  129. End If
  130.  
  131.  
  132. If intcard3 = intcard4 Then 'checking the cards for pairs
  133. intwinnings = intwinnings + 1 'stating the if a double is found, the winner receives $1 for each pair
  134. lblwinnings.Caption = intwinnings 'updating the onscreen total
  135. End If
  136.  
  137.  
  138. If intcard1 = intcard3 Then 'checking the cards for pairs
  139. intwinnings = intwinnings + 1 'stating the if a double is found, the winner receives $1 for each pair
  140. lblwinnings.Caption = intwinnings 'updating the onscreen total
  141. End If
  142.  
  143.  
  144.  
  145. If intcard1 = intcard4 Then 'checking the cards for pairs
  146. intwinnings = intwinnings + 1 'stating the if a double is found, the winner receives $1 for each pair
  147. lblwinnings.Caption = intwinnings 'updating the onscreen total
  148. End If
  149.  
  150.  
  151. If intcard2 = intcard4 Then 'checking the cards for pairs
  152. intwinnings = intwinnings + 1 'stating the if a double is found, the winner receives $1 for each pair
  153. lblwinnings.Caption = intwinnings 'updating the onscreen total
  154. End If
  155. End If
  156. End If
  157.  
  158.  
  159. End Sub
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nomiree is offline Offline
1 posts
since Jun 2005
Jun 15th, 2005
0

Re: Argument Not Optional message in VB

Quote originally posted by Nomiree ...
Sorry, I am a beginner at Visual Basic, and have had to create this project as part of a school task. It keeps coming up with "argument not optional" on the calls tp checkcards and determinewinnings. I don't knkow what this means really, and I don't know how to fix it. Can you help??

Here is the code:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Option Explicit
  2.  
  3. Private Sub cmdDraw_Click()
  4. 'subroutine to "draw" the cards
  5.  
  6. Call GenerateCards 'calling the GenerateCards subroutine
  7. Call CheckCards 'calling the CheckCards subroutine
  8. Call DetermineWinnings 'calling the DetermineWinnings subroutine
  9.  
  10. End Sub
  11.  
  12. Private Sub cmdStart_Click()
  13. 'subroutine to activate the program when start is clicked
  14.  
  15. cmdDraw.Enabled = True 'enabling the "Draw" command button
  16.  
  17. Dim intwinnings As Integer 'declaring the intwinnings variable as an integer
  18. intwinnings = 0 'setting intwinnings to 0
  19. lblwinnings.Caption = intwinnings 'making the lblwinnings caption 0
  20.  
  21. Randomize 'Telling the program to generate random numbers
  22.  
  23. End Sub
  24.  
  25. Sub GenerateCards()
  26. 'subroutine to generate the random numbers for the variables
  27.  
  28. Dim intcard1, intcard2, intcard3, intcard4 As Integer 'Declaring the variables as integers
  29.  
  30. intcard1 = Int(Rnd * 4) + 1 'making the intcard1 variable equal to a random number between 1 & 2
  31. intcard2 = Int(Rnd * 4) + 1 'making the intcard2 variable equal to a random number between 1 & 2
  32. intcard3 = Int(Rnd * 4) + 1 'making the intcard3 variable equal to a random number between 1 & 2
  33. intcard4 = Int(Rnd * 4) + 1 'making the intcard4 variable equal to a random number between 1 & 2
  34.  
  35. End Sub
  36.  
  37. Sub CheckCards(intcard1, intcard2, intcard3, intcard4 As Integer)
  38. 'subroutine to display image according to the values of the random numbers generated in the GenerateCards subroutine
  39.  
  40. If intcard1 = 1 Then 'Checking if the intcard1 variable is a 1 and if it is, generating a diamond card
  41. imgcard1.Picture = imgdiamond.Picture
  42. Else
  43. If intcard1 = 2 Then 'Checking if the intcard1 variable is a 2 and if it is, generating a hearts card
  44. imgcard1.Picture = imgheart.Picture
  45. Else
  46. If intcard1 = 3 Then
  47. imgcard1.Picture = imgclub.Picture 'Checking if the intcard1 variable is a 3 and if it is, generating a clubs card
  48. Else
  49. If intcard1 = 4 Then
  50. imgcard1.Picture = imgspade.Picture 'Checking if the intcard1 variable is a 4 and if it is, generating a spades card
  51. End If
  52. End If
  53. End If
  54. End If
  55.  
  56.  
  57. If intcard2 = 1 Then 'Checking if the intcard2 variable is a 1 and if it is, generating a diamonds card
  58. imgcard2.Picture = imgdiamond.Picture
  59. Else
  60. If intcard2 = 2 Then 'Checking if the intcard2 variable is a 2 and if it is, generating a hearts card
  61. imgcard2.Picture = imgheart.Picture
  62. Else
  63. If intcard2 = 3 Then 'Checking if the intcard2 variable is a 3 and if it is, generating a clubs card
  64. imgcard2.Picture = imgclub.Picture
  65. Else
  66. If intcard2 = 4 Then 'Checking if the intcard2 variable is a 4 and if it is, generating a spades card
  67. imgcard2.Picture = imgspade.Picture
  68. End If
  69. End If
  70. End If
  71. End If
  72.  
  73.  
  74. If intcard3 = 1 Then 'Checking if the intcard3 variable is a 1 and if it is, generating a diamonds card
  75. imgcard3.Picture = imgdiamond.Picture
  76. Else
  77. If intcard3 = 2 Then 'Checking if the intcard3 variable is a 2 and if it is, generating a hearts card
  78. imgcard3.Picture = imgheart.Picture
  79. Else
  80. If intcard3 = 3 Then 'Checking if the intcard3 variable is a 3 and if it is, generating a clubs card
  81. imgcard3.Picture = imgclub.Picture
  82. Else
  83. If intcard3 = 4 Then 'Checking if the intcard3 variable is a 4 and if it is, generating a spades card
  84. imgcard3.Picture = imgspade.Picture
  85. End If
  86. End If
  87. End If
  88. End If
  89.  
  90.  
  91. If intcard4 = 1 Then 'Checking if the intcard4 variable is a 1 and if it is, generating a diamonds card
  92. imgcard4.Picture = imgdiamond.Picture
  93. Else
  94. If intcard4 = 2 Then 'Checking if the intcard4 variable is a 2 and if it is, generating a hearts card
  95. imgcard4.Picture = imgheart.Picture
  96. Else
  97. If intcard4 = 3 Then 'Checking if the intcard4 variable is a 3 and if it is, generating a clubs card
  98. imgcard4.Picture = imgclub.Picture
  99. Else
  100. If intcard4 = 4 Then 'Checking if the intcard4 variable is a 4 and if it is, generating a spades card
  101. imgcard4.Picture = imgspade.Picture
  102. End If
  103. End If
  104. End If
  105. End If
  106.  
  107. End Sub
  108.  
  109. Sub DetermineWinnings(intcard1, intcard2, intcard3, intcard4, intwinnings As Integer)
  110. 'subroutine to calculate, and keep tally of the user's winnings
  111.  
  112. If intcard1 = intcard2 = intcard3 = intcard4 Then 'Checking the cards for four of the same
  113. intwinnings = intwinnings + 5 'stating that if a set of four is found, the winner receives $5
  114. lblwinnings.Caption = intwinnings 'Updating the onscreen total
  115. Else
  116. If intcard1 = intcard2 = intcard3 Or intcard2 = intcard3 = intcard4 Or intcard1 = intcard2 = intcard4 Or intcard1 = intcard3 = intcard4 Then 'checking the cards for triplets
  117. intwinnings = intwinnings + 3 'stating that if a triplet is found, the winner receives $3
  118. lblwinnings.Caption = intwinnings 'updating the onscreen total
  119. Else
  120. If intcard1 = intcard2 Then 'checking the cards for pairs
  121. intwinnings = intwinnings + 1 'stating the if a double is found, the winner receives $1 for each pair
  122. lblwinnings.Caption = intwinnings 'updating the onscreen total
  123. End If
  124.  
  125.  
  126. If intcard2 = intcard3 Then 'checking the cards for pairs
  127. intwinnings = intwinnings + 1 'stating the if a double is found, the winner receives $1 for each pair
  128. lblwinnings.Caption = intwinnings 'updating the onscreen total
  129. End If
  130.  
  131.  
  132. If intcard3 = intcard4 Then 'checking the cards for pairs
  133. intwinnings = intwinnings + 1 'stating the if a double is found, the winner receives $1 for each pair
  134. lblwinnings.Caption = intwinnings 'updating the onscreen total
  135. End If
  136.  
  137.  
  138. If intcard1 = intcard3 Then 'checking the cards for pairs
  139. intwinnings = intwinnings + 1 'stating the if a double is found, the winner receives $1 for each pair
  140. lblwinnings.Caption = intwinnings 'updating the onscreen total
  141. End If
  142.  
  143.  
  144.  
  145. If intcard1 = intcard4 Then 'checking the cards for pairs
  146. intwinnings = intwinnings + 1 'stating the if a double is found, the winner receives $1 for each pair
  147. lblwinnings.Caption = intwinnings 'updating the onscreen total
  148. End If
  149.  
  150.  
  151. If intcard2 = intcard4 Then 'checking the cards for pairs
  152. intwinnings = intwinnings + 1 'stating the if a double is found, the winner receives $1 for each pair
  153. lblwinnings.Caption = intwinnings 'updating the onscreen total
  154. End If
  155. End If
  156. End If
  157.  
  158.  
  159. End Sub

*******************************************************

where are trying to compare the values of:

If intcard1 = intcard2 = intcard3 = intcard4 ???

if you want to compare the four values try doing this:


if intcard1 = intcard2 and intcard1 = intcard3 and intcard1 = intcard4 then that will be for 4 of the same...(hope i am right)


now for the 3 of the same:

if intcard1 = intcard2 and intcard1 = intcard3 or intcard1 = intcard3 and intcard1 = intcard4 then


hope that one works for you...good luck.
Reputation Points: 11
Solved Threads: 0
Light Poster
vhinehds is offline Offline
29 posts
since May 2005
Jun 15th, 2005
0

Re: Argument Not Optional message in VB

'argument not optional' basically just means 'you can't do it like this'.

For all these comparisons, you could use other methods such as Select Case, or loops within loops, to make the code easier to read, but of course that comes with experience.

One thing I think I should point out is, when you declare several variables on the same line, you need to state the variable type for each one. If the VarType is not stated, it will default to the Variant type.
e.g.

Dim intCard1, intCard2, intCard3, intCard4 As Integer .....incorrect

Dim intCard1 As Integer, intCard2 As Integer, intCard3 As Integer, intCard4 As Integer......Correct
Reputation Points: 11
Solved Threads: 2
Junior Poster in Training
w00dy is offline Offline
70 posts
since Jun 2005
Jun 16th, 2005
0

Re: Argument Not Optional message in VB

if you are getting this where you say, it means that checkcards wants a variable sent to it:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Call CheckCards int1,int2, int3 ,int4 'calling the CheckCards subroutine
  2. Call DetermineWinnings int1,int2, int3 ,int4 'calling the DetermineWinnings subroutine
you may want to create a global variable for the cards so you won't have to worry about passing parameters to subs.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Global intcard1 as integer
  2. global intcard2 as integer
  3. global intcard3 as integer
  4. global intcard4 As Integer
or you may want to declare the variables as integer in the sub

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Sub CheckCards(intcard1 As Integer, intcard2 As Integer, intcard3 As Integer, intcard4 As Integer)
Reputation Points: 20
Solved Threads: 5
Junior Poster
jwshepherd is offline Offline
123 posts
since Jun 2005
Jun 16th, 2005
0

Re: Argument Not Optional message in VB

Yes, if these variables are not used in any other forms it would be simpler to declare them with the Dim statement directly after 'Option Explicit', instead of inside the sub.
As far as I know, if you declare a variable inside a sub, it is not recognised anywhere else, even if you use Global or Public. Someone please correct me if I'm wrong !
Reputation Points: 11
Solved Threads: 2
Junior Poster in Training
w00dy is offline Offline
70 posts
since Jun 2005
Jun 16th, 2005
0

Re: Argument Not Optional message in VB

*Nods*

jwshepherd is hitting real close to home with that. You should take his advice.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Jun 16th, 2005
0

Re: Argument Not Optional message in VB

A global variable has to be defined in a code module. A local variable gets dimensioned within the sub, and it's "scope" only extends within the sub. A Public Variable gets declared within the declarations section of the form, and it's scope is all procedures in the form. So, if you need a temporary variable, that only needs to be used in one procedure... use dim in that procedure. If you need a variable that the form can use... say, a variable that an OK and Cancel button can both have access to, then you would need a public/form-wide variable. If you want one that the entire project can use (spanning multiple forms) then you need a global variable (declared in a module).
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Jun 16th, 2005
0

Re: Argument Not Optional message in VB

Yes Comatose is correct.

If int1 is declared in a sub, it's value can only be used in that sub. ONce the program leaves that sub, the value is erased.

I forgot to tell you to add a module to your project to add the global variables.

Good luck
Reputation Points: 20
Solved Threads: 5
Junior Poster
jwshepherd is offline Offline
123 posts
since Jun 2005
Jun 16th, 2005
0

Re: Argument Not Optional message in VB

You can add all kinds of great stuff in code modules too. You can have functions and subs accessible by the entire program, along with variables, constants, type declarations, and API calls. As soon as I start a new project, I add a code module (it's actually a standard module I built so that VB can use certain subs and functions that come in other language [such as push and pop]) right off the bat, so that I know I at least have one...
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Add an item to a listview using API
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Need help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC