Microsoft KB Archive/129872

= PRB: Wrong Number of Arguments Error When Call Math Functions =

Article ID: 129872

Article Last Modified on 12/9/2003

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q129872



SYMPTOMS
Adding a reference to Microsoft Excel's Type Library from Visual Basic version 4.0 and then early binding an instance of Microsoft Excel's Application Object results in the following error message, when calling a Math function on that object:

Wrong number of arguments or invalid property assignment.



CAUSE
All the math functions in the Microsoft Excel Type Library are typed as receiving no arguments, but most of them do have arguments. This is displayed in the help string for the corresponding math function in Visual Basic's Object Browser.



RESOLUTION
Use late binding with a generic object. For example, use the following code in the Form_Click event in the "Steps to Reproduce Behavior" section of this article: Dim XLApp As Object Set XLApp = CreateObject("excel.application") z = XLApp.Atan2(3, 4) MsgBox Str$(z)



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Start a new project in Visual Basic. Form1 is created by default.  Add the following code to the Form_Click event: Dim XLApp As Excel.Application Set XLApp = CreateObject("excel.application") z = XLApp.Atan2(3, 4) ' Get an error here on wrong number of args. MsgBox Str$(z)  Choose References from the Tools menu. Select the reference for Microsoft Excel 5.0 Object Library, and then click the OK button. Press the F5 key to Run the program. You will get an error message on the line that calls the Atan2 function.

Keywords: kberrmsg kbprogramming kbprb KB129872

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.