ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   CVErr, Excel and VB .NET (https://www.excelbanter.com/excel-programming/278470-cverr-excel-vbulletin-net.html)

Howard Kaikow

CVErr, Excel and VB .NET
 
Many Excel macros/add-ins rely on the use of the VB/VBA CVErr function.

Alas, VB .NET does not support the CVErr function.

Does Excel 2003, Office 2003 or Visual Studio Tools for Office provide a
substitute?

--
http://www.standards.com/; See Howard Kaikow's web site.



Keith Willshaw

CVErr, Excel and VB .NET
 

"Howard Kaikow" wrote in message
...
Many Excel macros/add-ins rely on the use of the VB/VBA CVErr function.

Alas, VB .NET does not support the CVErr function.

Does Excel 2003, Office 2003 or Visual Studio Tools for Office provide a
substitute?


But in .net you can achieve the same functionallity
by using the exception handling routines it does support

In VB6 you'd call a VB error code as follows

Function CalculateDouble(Number)
If IsNumeric(Number) Then
CalculateDouble = Number * 2 ' Return result.
Else
CalculateDouble = CVErr(2001) ' Return a user-defined error
End If ' number.
End Function


In .net you'd throw an exception to do the same thing
with the call

Throw new InvalidOperationException("Invalid Input to Function")

Keith



Howard Kaikow

CVErr, Excel and VB .NET
 
Yes, I recall, perhaps incorrectly, that special error codes in Excel, such
as xlErrValue, required use of a Variant.

--
http://www.standards.com/; See Howard Kaikow's web site.
"Keith Willshaw" wrote in message
...

"Howard Kaikow" wrote in message
...
Many Excel macros/add-ins rely on the use of the VB/VBA CVErr function.

Alas, VB .NET does not support the CVErr function.

Does Excel 2003, Office 2003 or Visual Studio Tools for Office provide a
substitute?


But in .net you can achieve the same functionallity
by using the exception handling routines it does support

In VB6 you'd call a VB error code as follows

Function CalculateDouble(Number)
If IsNumeric(Number) Then
CalculateDouble = Number * 2 ' Return result.
Else
CalculateDouble = CVErr(2001) ' Return a user-defined error
End If ' number.
End Function


In .net you'd throw an exception to do the same thing
with the call

Throw new InvalidOperationException("Invalid Input to Function")

Keith






All times are GMT +1. The time now is 12:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com