Code to rerun an operation in the event of an error

Posted on 2007-08-10
Last Modified: 2008-01-09
In my code I have an operation that consistantly faily, but if I go in debug mode and just hit F8 again to rerun it, it works fine.  I am new to programming and am looking for a way that I can have this operation retry (up to 5 times) before it throws an exception.  The error is the last line of the code posted below where I pass the prompt value to the business objects report.


        Dim BusObjApp As New busobj.Application
        BusObjApp.LoginAs("jhaft", "jhaft", False)
        Dim BusObjDoc As New busobj.Document
        Dim promptName As String = ""
        Dim promptValue As String = ""
        Dim promptName2 As String = ""
        Dim promptValue2 As String = ""
        Dim PriorBusinessDayShort As String = ""
        Dim PriorBusinessDayLong As String = ""
        Dim LasyYearBusinessDayLong As String = ""

        PriorBusinessDayShort = "8/9/07"
        PriorBusinessDayLong = "8/9/2007"
        LasyYearBusinessDayLong = "8/10/2006"

        BusObjApp.Interactive = True
        BusObjApp.Visible = True

        BusObjDoc = BusObjApp.Documents.Open("M:\Corporate\Finance\Corporate Finance\Daily Reporting\NIFO\Daily NIFO Reports\Selected Styles Daily Sales Report Final.Rep", NoAutomaticRefresh:=True)

        promptName = "prior business date"
        promptValue = PriorBusinessDayLong
        BusObjApp.Variables.Item(promptName).Value = promptValue.ToString
Question by:collages
    LVL 10

    Accepted Solution

    before you do that, try adding Application.DoEvents right before that line:

    BusObjApp.Variables.Item(promptName).Value = promptValue.ToString
    LVL 1

    Author Comment

    Tried that, no luck.

    When it hits that line where I pass the prompt values I SOMETIMES get this error:

    Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))

    When that happens it goes into debug mode....heres the strange part....if I wait, say 20 seconds, then resume the code, it works fine.  However, if I increase the sleep to as much as 1 monute it doesnt needs to first get the error, then wait, then when I resume it, the thing works find.

    Any ideas what might be going on here?

    LVL 10

    Expert Comment

    LVL 1

    Author Comment

    Ok....Im new to this and I read that article.  I dont understand what I need to do.

    I added the COM reference and added:

    Imports EnvDTE
    Imports EnvDTE80

    to my application.

    Then I did this:

    Dim MyTest As EnvDTE80.DTE2

    What im stuck on is in the example (which is in C#) they do this:

    dte = (EnvDTE80.DTE2)obj;

    What is the equivalent in
    LVL 10

    Expert Comment


    SET dte = CType(obj, EnvDTE80.DTE2)


    SET dte = DirectCast(obj, EnvDTE80.DTE2)

    I'm also not very good at C#... adapted from here:
    LVL 1

    Author Comment

    Ok...I think im just in way over my head here...ill revisit this in a few months after ive learned a bit more.

    thanks for your help
    LVL 10

    Expert Comment

    np.! Thahnks, I'm glad I coud help ;-)

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now