CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: VB HRSEULTS

  1. #1
    Join Date
    Jan 2001
    Location
    Switzerland
    Posts
    6

    VB HRSEULTS

    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?


  2. #2
    Join Date
    Apr 1999
    Location
    VA BEACH
    Posts
    467

    Re: VB HRSEULTS

    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

  3. #3
    Join Date
    Jan 2001
    Location
    Switzerland
    Posts
    6

    Re: VB HRSEULTS

    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.



  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: VB HRSEULTS

    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.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  5. #5
    Join Date
    Apr 1999
    Location
    VA BEACH
    Posts
    467

    Re: VB HRSEULTS

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured