asked on
Wrong number of arguments ...
I am getting an error on the following command:
"Wrong number of arguments or invalid property assignment."
str = Format(I, "00")
I have used this function lots of times, but when I use to get errors like this I was using VB6 and usually had a library not loading correctly (or not included).
Not sure how to check what libraries are loading or loaded in VBA
Any help is appreciated.
ASKER
No, Pretty sure I wouldn't make that mistake, but I searched anyway.
But Yes, The Macro recorder did.
Nice catch !
Thank You.
ASKER
Why didn't I get some type of Vague name error ?Unfortunately that's the way it is.
In any case you’re welcome and I’m glad I was able to help.
If you expand the “Full Biography" section of my profile you’ll find links to some articles I’ve written that may interest you.
Marty - Microsoft MVP 2009 to 2017
Experts Exchange Most Valuable Expert (MVE) 2015 and 2017
Experts Exchange Distinguished Expert in Excel 2018, 2021, 2022
Experts Exchange Distinguished Expert in Microsoft Office 2022
Experts Exchange Distinguished Expert in VBA 2022
Experts Exchange Top Expert VBA 2018 to 2022
Experts Exchange Top Expert Visual Basic Classic 2012 to 2022
ASKER
Q: Why didn't I get some type of Vague name error ?
A: I put that on M$, why would the macro-recorder let and/or create a sub that is the same as a reserved word ?
Q: Does VBA support overloading ?
Does VBA support overloading ?I don't know.
It does not.
Jim.
I should add that you can come close with the use of optional arguments, but it's not quite the same thing as overloading.
With optional arguments, you can call the *same* procedure different ways, but that procedure is defined only once.
You can also used named arguments with vba. Given:
Sub PassArgs(strName As String, intAge As Integer, dteBirth As Date)
Debug.Print strName, intAge, dteBirth
End Sub
You would normally call it like this:
PassArgs "Mary", 29, #2-21-69#
But you can also call it like this:
PassArgs intAge:=29, dteBirth:=#2/21/69#, strName:="Mary"
which helps shorten the call if you have defined a lot of optional arguments.
Jim.
ASKER
Funny how it appears that functions declared in the app appear to replace functions found in libraries, I suppose that is intentional so you can make your own function upgrades ?
Jim, I do see overloading examples like this online. If your passing and returning a bunch of variants, seems like it would be prone to errors.
Wonder if that's what .Net does under hood for you ?
Thanks
That's not overloading, at least as I know it. Overloading would look like this:
Public Sub Foo(strStart as string, strEnd as string)
' do something
End Sub
Public Sub Foo(strStart as string, strEnd As String, strInterval as string)
' do something totally different and work with the interval
End Sub
Which VBA doesn't allow. But as I said, optional arguments do come close:
Public Sub Foo(strStart as string, strEnd As String, optional strInterval as string)
' Do something, and maybe work with the interval
End Sub
but you are always calling the same block of code, not different ones as you would with true overloading.
Jim.
<<Not sure how to check what libraries are loading or loaded in VBA >>
With the code window open, it's tools/references on the menubar.
Jim.