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:
Can you critique and offer advise or suggestion?
Thanks in advance.
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.