Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Best To Handle Sequential Calls

Status
Not open for further replies.

vbcnew55

Technical User
Mar 2, 2008
7
CA
Hi,

I was not sure what to use as a search term to find the answer to my question so I created this thread.

I would like to know how you structure your code when you need to do several things.

I typically write Functions instead of Subs because I want to know that a preceding call was successful before running the next line of code. Therefore, each function call returns a [tt]TRUE[/tt] to indicate that it succeeded in accomplishing its task or [tt]FALSE[/tt] to indicate that it did not successfully finish its task or an error occurred.

Example Code:
Code:
Private Function doWork() As Boolean
    Try
        If toDo1() = False Then Throw New Exception
        If toDo2() = False Then Throw New Exception
        Return True
    Catch ex As Exception
        Return False
    End Try
End Function

Private Function toDo1() As Boolean
    Try
        ' code here to do whatever needs to be done
        Return True
    Catch ex As Exception
        Return False
    End Try
End Function

Private Function toDo2() As Boolean
    Try
        ' code here to do whatever needs to be done
        Return True
    Catch ex As Exception
        Return False
    End Try
End Function

Can you critique and offer advise or suggestion?

Thanks in advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top