RSS Forums RSS
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 6635 | Replies: 8
Reply
Join Date: Jun 2005
Posts: 1
Reputation: Nomiree is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Nomiree Nomiree is offline Offline
Newbie Poster

Help Argument Not Optional message in VB

  #1  
Jun 15th, 2005
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:

Option Explicit

Private Sub cmdDraw_Click()
'subroutine to "draw" the cards

Call GenerateCards      'calling the GenerateCards subroutine
Call CheckCards         'calling the CheckCards subroutine
Call DetermineWinnings  'calling the DetermineWinnings subroutine

End Sub

Private Sub cmdStart_Click()
'subroutine to activate the program when start is clicked

cmdDraw.Enabled = True              'enabling the "Draw" command button

Dim intwinnings As Integer          'declaring the intwinnings variable as an integer
intwinnings = 0                     'setting intwinnings to 0
lblwinnings.Caption = intwinnings   'making the lblwinnings caption 0

Randomize                           'Telling the program to generate random numbers

End Sub

Sub GenerateCards()
'subroutine to generate the random numbers for the variables

Dim intcard1, intcard2, intcard3, intcard4 As Integer 'Declaring the variables as integers

intcard1 = Int(Rnd * 4) + 1     'making the intcard1 variable equal to a random number between 1 & 2
intcard2 = Int(Rnd * 4) + 1     'making the intcard2 variable equal to a random number between 1 & 2
intcard3 = Int(Rnd * 4) + 1     'making the intcard3 variable equal to a random number between 1 & 2
intcard4 = Int(Rnd * 4) + 1     'making the intcard4 variable equal to a random number between 1 & 2

End Sub

Sub CheckCards(intcard1, intcard2, intcard3, intcard4 As Integer)
'subroutine to display image according to the values of the random numbers generated in the GenerateCards subroutine

If intcard1 = 1 Then                                    'Checking if the intcard1 variable is a 1 and if it is, generating a diamond card
    imgcard1.Picture = imgdiamond.Picture
Else
    If intcard1 = 2 Then                                'Checking if the intcard1 variable is a 2 and if it is, generating a hearts card
        imgcard1.Picture = imgheart.Picture
    Else
        If intcard1 = 3 Then
            imgcard1.Picture = imgclub.Picture          'Checking if the intcard1 variable is a 3 and if it is, generating a clubs card
        Else
            If intcard1 = 4 Then
                imgcard1.Picture = imgspade.Picture     'Checking if the intcard1 variable is a 4 and if it is, generating a spades card
            End If
        End If
    End If
End If


If intcard2 = 1 Then                                     'Checking if the intcard2 variable is a 1 and if it is, generating a diamonds card
    imgcard2.Picture = imgdiamond.Picture
Else
    If intcard2 = 2 Then                                 'Checking if the intcard2 variable is a 2 and if it is, generating a hearts card
        imgcard2.Picture = imgheart.Picture
    Else
        If intcard2 = 3 Then                             'Checking if the intcard2 variable is a 3 and if it is, generating a clubs card
            imgcard2.Picture = imgclub.Picture
        Else
            If intcard2 = 4 Then                         'Checking if the intcard2 variable is a 4 and if it is, generating a spades card
                imgcard2.Picture = imgspade.Picture
            End If
        End If
    End If
End If


If intcard3 = 1 Then                                     'Checking if the intcard3 variable is a 1 and if it is, generating a diamonds card
    imgcard3.Picture = imgdiamond.Picture
Else
    If intcard3 = 2 Then                                 'Checking if the intcard3 variable is a 2 and if it is, generating a hearts card
        imgcard3.Picture = imgheart.Picture
    Else
        If intcard3 = 3 Then                             'Checking if the intcard3 variable is a 3 and if it is, generating a clubs card
            imgcard3.Picture = imgclub.Picture
        Else
            If intcard3 = 4 Then                         'Checking if the intcard3 variable is a 4 and if it is, generating a spades card
                imgcard3.Picture = imgspade.Picture
            End If
        End If
    End If
End If


If intcard4 = 1 Then                                     'Checking if the intcard4 variable is a 1 and if it is, generating a diamonds card
    imgcard4.Picture = imgdiamond.Picture
Else
    If intcard4 = 2 Then                                 'Checking if the intcard4 variable is a 2 and if it is, generating a hearts card
        imgcard4.Picture = imgheart.Picture
    Else
        If intcard4 = 3 Then                             'Checking if the intcard4 variable is a 3 and if it is, generating a clubs card
            imgcard4.Picture = imgclub.Picture
        Else
            If intcard4 = 4 Then                         'Checking if the intcard4 variable is a 4 and if it is, generating a spades card
                imgcard4.Picture = imgspade.Picture
            End If
        End If
    End If
End If

End Sub

Sub DetermineWinnings(intcard1, intcard2, intcard3, intcard4, intwinnings As Integer)
'subroutine to calculate, and keep tally of the user's winnings

If intcard1 = intcard2 = intcard3 = intcard4 Then   'Checking the cards for four of the same
    intwinnings = intwinnings + 5       'stating that if a set of four is found, the winner receives $5
    lblwinnings.Caption = intwinnings   'Updating the onscreen total
Else
    If intcard1 = intcard2 = intcard3 Or intcard2 = intcard3 = intcard4 Or intcard1 = intcard2 = intcard4 Or intcard1 = intcard3 = intcard4 Then    'checking the cards for triplets
        intwinnings = intwinnings + 3       'stating that if a triplet is found, the winner receives $3
        lblwinnings.Caption = intwinnings   'updating the onscreen total
    Else
        If intcard1 = intcard2 Then             'checking the cards for pairs
            intwinnings = intwinnings + 1       'stating the if a double is found, the winner receives $1 for each pair
            lblwinnings.Caption = intwinnings   'updating the onscreen total
        End If
        
        
        If intcard2 = intcard3 Then           'checking the cards for pairs
            intwinnings = intwinnings + 1       'stating the if a double is found, the winner receives $1 for each pair
            lblwinnings.Caption = intwinnings   'updating the onscreen total
        End If
        
        
        If intcard3 = intcard4 Then             'checking the cards for pairs
            intwinnings = intwinnings + 1       'stating the if a double is found, the winner receives $1 for each pair
            lblwinnings.Caption = intwinnings   'updating the onscreen total
        End If
        
        
        If intcard1 = intcard3 Then             'checking the cards for pairs
            intwinnings = intwinnings + 1       'stating the if a double is found, the winner receives $1 for each pair
            lblwinnings.Caption = intwinnings   'updating the onscreen total
        End If
            
            
            
        If intcard1 = intcard4 Then         'checking the cards for pairs
            intwinnings = intwinnings + 1       'stating the if a double is found, the winner receives $1 for each pair
            lblwinnings.Caption = intwinnings   'updating the onscreen total
        End If
            
            
        If intcard2 = intcard4 Then           'checking the cards for pairs
            intwinnings = intwinnings + 1       'stating the if a double is found, the winner receives $1 for each pair
            lblwinnings.Caption = intwinnings   'updating the onscreen total
        End If
    End If
End If
        

End Sub
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2005
Posts: 29
Reputation: vhinehds is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
vhinehds's Avatar
vhinehds vhinehds is offline Offline
Light Poster

Re: Argument Not Optional message in VB

  #2  
Jun 15th, 2005
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:

Option Explicit

Private Sub cmdDraw_Click()
'subroutine to "draw" the cards

Call GenerateCards      'calling the GenerateCards subroutine
Call CheckCards         'calling the CheckCards subroutine
Call DetermineWinnings  'calling the DetermineWinnings subroutine

End Sub

Private Sub cmdStart_Click()
'subroutine to activate the program when start is clicked

cmdDraw.Enabled = True              'enabling the "Draw" command button

Dim intwinnings As Integer          'declaring the intwinnings variable as an integer
intwinnings = 0                     'setting intwinnings to 0
lblwinnings.Caption = intwinnings   'making the lblwinnings caption 0

Randomize                           'Telling the program to generate random numbers

End Sub

Sub GenerateCards()
'subroutine to generate the random numbers for the variables

Dim intcard1, intcard2, intcard3, intcard4 As Integer 'Declaring the variables as integers

intcard1 = Int(Rnd * 4) + 1     'making the intcard1 variable equal to a random number between 1 & 2
intcard2 = Int(Rnd * 4) + 1     'making the intcard2 variable equal to a random number between 1 & 2
intcard3 = Int(Rnd * 4) + 1     'making the intcard3 variable equal to a random number between 1 & 2
intcard4 = Int(Rnd * 4) + 1     'making the intcard4 variable equal to a random number between 1 & 2

End Sub

Sub CheckCards(intcard1, intcard2, intcard3, intcard4 As Integer)
'subroutine to display image according to the values of the random numbers generated in the GenerateCards subroutine

If intcard1 = 1 Then                                    'Checking if the intcard1 variable is a 1 and if it is, generating a diamond card
    imgcard1.Picture = imgdiamond.Picture
Else
    If intcard1 = 2 Then                                'Checking if the intcard1 variable is a 2 and if it is, generating a hearts card
        imgcard1.Picture = imgheart.Picture
    Else
        If intcard1 = 3 Then
            imgcard1.Picture = imgclub.Picture          'Checking if the intcard1 variable is a 3 and if it is, generating a clubs card
        Else
            If intcard1 = 4 Then
                imgcard1.Picture = imgspade.Picture     'Checking if the intcard1 variable is a 4 and if it is, generating a spades card
            End If
        End If
    End If
End If


If intcard2 = 1 Then                                     'Checking if the intcard2 variable is a 1 and if it is, generating a diamonds card
    imgcard2.Picture = imgdiamond.Picture
Else
    If intcard2 = 2 Then                                 'Checking if the intcard2 variable is a 2 and if it is, generating a hearts card
        imgcard2.Picture = imgheart.Picture
    Else
        If intcard2 = 3 Then                             'Checking if the intcard2 variable is a 3 and if it is, generating a clubs card
            imgcard2.Picture = imgclub.Picture
        Else
            If intcard2 = 4 Then                         'Checking if the intcard2 variable is a 4 and if it is, generating a spades card
                imgcard2.Picture = imgspade.Picture
            End If
        End If
    End If
End If


If intcard3 = 1 Then                                     'Checking if the intcard3 variable is a 1 and if it is, generating a diamonds card
    imgcard3.Picture = imgdiamond.Picture
Else
    If intcard3 = 2 Then                                 'Checking if the intcard3 variable is a 2 and if it is, generating a hearts card
        imgcard3.Picture = imgheart.Picture
    Else
        If intcard3 = 3 Then                             'Checking if the intcard3 variable is a 3 and if it is, generating a clubs card
            imgcard3.Picture = imgclub.Picture
        Else
            If intcard3 = 4 Then                         'Checking if the intcard3 variable is a 4 and if it is, generating a spades card
                imgcard3.Picture = imgspade.Picture
            End If
        End If
    End If
End If


If intcard4 = 1 Then                                     'Checking if the intcard4 variable is a 1 and if it is, generating a diamonds card
    imgcard4.Picture = imgdiamond.Picture
Else
    If intcard4 = 2 Then                                 'Checking if the intcard4 variable is a 2 and if it is, generating a hearts card
        imgcard4.Picture = imgheart.Picture
    Else
        If intcard4 = 3 Then                             'Checking if the intcard4 variable is a 3 and if it is, generating a clubs card
            imgcard4.Picture = imgclub.Picture
        Else
            If intcard4 = 4 Then                         'Checking if the intcard4 variable is a 4 and if it is, generating a spades card
                imgcard4.Picture = imgspade.Picture
            End If
        End If
    End If
End If

End Sub

Sub DetermineWinnings(intcard1, intcard2, intcard3, intcard4, intwinnings As Integer)
'subroutine to calculate, and keep tally of the user's winnings

If intcard1 = intcard2 = intcard3 = intcard4 Then   'Checking the cards for four of the same
    intwinnings = intwinnings + 5       'stating that if a set of four is found, the winner receives $5
    lblwinnings.Caption = intwinnings   'Updating the onscreen total
Else
    If intcard1 = intcard2 = intcard3 Or intcard2 = intcard3 = intcard4 Or intcard1 = intcard2 = intcard4 Or intcard1 = intcard3 = intcard4 Then    'checking the cards for triplets
        intwinnings = intwinnings + 3       'stating that if a triplet is found, the winner receives $3
        lblwinnings.Caption = intwinnings   'updating the onscreen total
    Else
        If intcard1 = intcard2 Then             'checking the cards for pairs
            intwinnings = intwinnings + 1       'stating the if a double is found, the winner receives $1 for each pair
            lblwinnings.Caption = intwinnings   'updating the onscreen total
        End If
        
        
        If intcard2 = intcard3 Then           'checking the cards for pairs
            intwinnings = intwinnings + 1       'stating the if a double is found, the winner receives $1 for each pair
            lblwinnings.Caption = intwinnings   'updating the onscreen total
        End If
        
        
        If intcard3 = intcard4 Then             'checking the cards for pairs
            intwinnings = intwinnings + 1       'stating the if a double is found, the winner receives $1 for each pair
            lblwinnings.Caption = intwinnings   'updating the onscreen total
        End If
        
        
        If intcard1 = intcard3 Then             'checking the cards for pairs
            intwinnings = intwinnings + 1       'stating the if a double is found, the winner receives $1 for each pair
            lblwinnings.Caption = intwinnings   'updating the onscreen total
        End If
            
            
            
        If intcard1 = intcard4 Then         'checking the cards for pairs
            intwinnings = intwinnings + 1       'stating the if a double is found, the winner receives $1 for each pair
            lblwinnings.Caption = intwinnings   'updating the onscreen total
        End If
            
            
        If intcard2 = intcard4 Then           'checking the cards for pairs
            intwinnings = intwinnings + 1       'stating the if a double is found, the winner receives $1 for each pair
            lblwinnings.Caption = intwinnings   'updating the onscreen total
        End If
    End If
End If
        

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.
Reply With Quote  
Join Date: Jun 2005
Posts: 70
Reputation: w00dy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 2
w00dy w00dy is offline Offline
Junior Poster in Training

Re: Argument Not Optional message in VB

  #3  
Jun 15th, 2005
'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
Reply With Quote  
Join Date: Jun 2005
Location: Texas
Posts: 120
Reputation: jwshepherd is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
jwshepherd's Avatar
jwshepherd jwshepherd is offline Offline
Junior Poster

Re: Argument Not Optional message in VB

  #4  
Jun 16th, 2005
if you are getting this where you say, it means that checkcards wants a variable sent to it:
Call CheckCards   int1,int2, int3 ,int4 'calling the CheckCards subroutine
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.
Global intcard1 as integer
global  intcard2 as integer
global intcard3 as integer
global intcard4 As Integer
or you may want to declare the variables as integer in the sub

Sub CheckCards(intcard1 As Integer, intcard2 As Integer, intcard3 As Integer, intcard4 As Integer)
Reply With Quote  
Join Date: Jun 2005
Posts: 70
Reputation: w00dy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 2
w00dy w00dy is offline Offline
Junior Poster in Training

Re: Argument Not Optional message in VB

  #5  
Jun 16th, 2005
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 !
Reply With Quote  
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 108
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: Argument Not Optional message in VB

  #6  
Jun 16th, 2005
*Nods*

jwshepherd is hitting real close to home with that. You should take his advice.
Reply With Quote  
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 108
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: Argument Not Optional message in VB

  #7  
Jun 16th, 2005
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).
Reply With Quote  
Join Date: Jun 2005
Location: Texas
Posts: 120
Reputation: jwshepherd is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
jwshepherd's Avatar
jwshepherd jwshepherd is offline Offline
Junior Poster

Re: Argument Not Optional message in VB

  #8  
Jun 16th, 2005
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
.: We may acquire liberty, but it is never recovered if it is lost :.
irc://irc.rizon.net/#itf
Reply With Quote  
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 108
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: Argument Not Optional message in VB

  #9  
Jun 16th, 2005
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...
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

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

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 11:31 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC