Code to rerun an operation in the event of an error

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.

Thanks.




        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
        Threading.Thread.Sleep(2000)
        BusObjApp.Variables.Item(promptName).Value = promptValue.ToString
LVL 1
collagesAsked:
Who is Participating?
 
DxpertConnect With a Mentor Commented:
before you do that, try adding Application.DoEvents right before that line:

Application.DoEvents()
Threading.Thread.Sleep(2000)
BusObjApp.Variables.Item(promptName).Value = promptValue.ToString

http://msdn2.microsoft.com/en-us/library/system.windows.forms.application.doevents.aspx
0
 
collagesAuthor Commented:
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 help....it 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?

0
 
DxpertCommented:
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
collagesAuthor Commented:
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 vb.net?
0
 
DxpertCommented:
Try:

SET dte = CType(obj, EnvDTE80.DTE2)

OR

SET dte = DirectCast(obj, EnvDTE80.DTE2)


I'm also not very good at C#... adapted from here:
http://www.codeproject.com/dotnet/CheatSheetCastingNET.asp
0
 
collagesAuthor Commented:
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
0
 
DxpertCommented:
np.! Thahnks, I'm glad I coud help ;-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.