Click to See Complete Forum and Search --> : VB HRSEULTS
Twinnie
March 26th, 2001, 08:21 AM
I have a COM wrapper class in VC++, with methods and properties exposed to VB.
I want to check the HRESULT value passed back from my methods, so that I can execute in VB according to the status of the COM Methods.
VB does not compile when I try to use "SUCCEEDED" or FAILED - it comes back with "Sub or Function not defined" error.
How can I check the HRESULT status in VB?
James Longstreet
March 27th, 2001, 09:30 AM
Visual Basic does not return HRESULTS from COM functions. Therefore functions SUCCEEDED and FAILED have no meaning in VB. You need to put error handlers around your VB code, then if an error occurs you will be able to handle it. Another alternative is code the methods with out params indicating success or failure; then you will know in your VB app if they succeeded or failed.
Jim Hewitt
Software Developer
Liberty Tax Service
www.LibertyTax.com
Twinnie
March 28th, 2001, 06:20 AM
Thanks,
I implemented the on error goto.. anyway, but I was curious to know if I could use HRESULTS. I suppose that the On error goto approach lets you group multiple methods in the VB. Using SUCCEEDED on each method call could end up being a little untidy I suppose.
Cimperiali
March 28th, 2001, 06:31 AM
Sorry if I mismatched the point but, if in same sub or function you need to enable different error handling routines, you can:
private sub testMymethods
on error goto errHandler1
myfirstmethod...
on error goto 0
on error goto errHandler2
mysecondmethod...
on error goto 0
on error goto errHandler3
...
exit sub
errHandler1:
(decide what to do..)
...
(resume something)
exit sub
errHandler2:
...
(resume something)
exit sub
errHandler3:
...
(resume something)
end sub
Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
James Longstreet
March 28th, 2001, 08:10 AM
HRESULTS give much more flexibility; as in testing for errors and such, but VB has VERY limmited error handling ability; but in VB.Net that should be greatly improved.
Jim Hewitt
Software Developer
Liberty Tax Service
www.LibertyTax.com
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.