473,320 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Argument not Optional

Good Morning! I am still very new to VBA, and I'm getting an error that I can't figure out with a basic code. Here's what I have at this point:

Option Compare Database
Option Explicit

Private Sub cmdLarger_Click()
FindLargestNumber
End Sub

Public Function FindLargestNumber(ByVal Number1 As Double, ByVal Number2 As Double)
Number1 = Val(txtOne.Value)
Number2 = Val(txtTwo.Value)

End Function


This is only the beginning of the code for a project, but when I click on the command button, I get "argument not optional". I think it might be how I've declared the function, but I'm not sure what I'm doing wrong. Any help you can provide would be amazing.

TJ
Mar 3 '10 #1
3 10029
ADezii
8,834 Expert 8TB
  1. It appears as though you wish to pass Values in the two Text Boxes to evaluate and see which, if any, is larger. In that case, the simplest approach would be:
    Expand|Select|Wrap|Line Numbers
    1. Public Function FindLargestNumber(ByVal Number1 As Double, ByVal Number2 As Double) As Variant
    2. If Number1 = Number2 Then
    3.   FindLargestNumber = Null
    4. ElseIf Number1 < Number2 Then
    5.   FindLargestNumber = Number2
    6. Else
    7.   FindLargestNumber = Number1
    8. End If
    9. End Function
  2. Function Call:
    Expand|Select|Wrap|Line Numbers
    1. Dim varRetVal As Variant
    2.  
    3. varRetVal = FindLargestNumber(Val(Me![txtOne]), (Val(Me![txtTwo]))
Mar 3 '10 #2
TheSmileyCoder
2,322 Expert Mod 2GB
In your function declaration:
Expand|Select|Wrap|Line Numbers
  1. Public Function FindLargestNumber(ByVal Number1 As Double, ByVal Number2 As Double)
  2. Number1 = Val(txtOne.Value)
  3. Number2 = Val(txtTwo.Value)
  4.  
  5. End Function
Your saying that the function expects input variables Number1 and Number2.

However when your calling the function:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdLarger_Click()
  2.   FindLargestNumber
  3. End Sub
You are NOT providing any input variables. And thats what your error message is telling you. That the variable (or argument) is not optional.
Mar 3 '10 #3
Thanks for your help! I'm still not sure I grasp the calling of the arguments concept, but I see how the code you gave me works, and I'm going to try it with a few different examples to gain practice!

TJ
Mar 3 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Alan Little | last post by:
Is it possible to make a by-reference argument optional in a UDF? When I try to assign it a default value in the definition, I get a parse error, "unexpected '='". PHP itself has optional by-ref...
1
by: Martin Miller | last post by:
In section "3.27 new -- Creation of runtime internal objects" of the documentation that comes with Python 2.4 it says: > instancemethod(function, instance, class) > > This function will return...
3
by: CoolPint | last post by:
Can anyone explain how I can make the following function accept an default arguement for the last parameter, which should be an optional functor? template <typename T, typename FUNCTOR> void...
0
by: Bobbak | last post by:
Hello All, I could really use some help with this bit of code I am working on, every time I come to execute it I get an error that says "Compile Error: Argument not optional". Now I am using...
2
by: Zoury | last post by:
Hi there! I'm using a COM component from my C# application and I can't get it to work properly. I get a COMException (Invalid procedure call or argument) on this line : //***...
9
by: tiger79 | last post by:
Hi, I would like to know if there exists something like the Optional argument in VB for C# ??? thanx...
4
by: Joe HM | last post by:
Hello - I realize that there is no more IsMissing function in VB.NET but how can I have a boolean argument that is optional and in the code I need to determine whether it was passed it or not? ...
4
by: Patient Guy | last post by:
Does anyone have any coding rules they follow when doing argument checking? When arguments fail during check, do you return from the call with an ambiguous return value, or do you throw...
10
by: Immortalist | last post by:
Various aquisition devices that guide learning along particular pathways towards human biases. And as E.O. Wilson might say mental development appears to be genetically constrained. (1) Language...
2
by: cheesecaker | last post by:
In this random practice script I was doing, I was passing some variables to the script with the URL, which means the $_GET method. <?php header("Content-type: image/png"); $textinput =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.