Boolean complete RRS feed

  • Question

  • am looking at code from the 90s.  all the modules, and even some routines within a module, have a variable Bln as Boolean - where each module begins with If Bln = True        and likewise the routines end with Bln = True

    so it seems like a circuit breaker concept where the next module won't fire if the prior doesn't finish.

    each module also has a very uniform error trap

    am just wondering if this approach was or possibly still is common - or whether I am misinterpreting the role of this Boolean variable....

    Thursday, February 14, 2019 2:23 AM

All replies

  • Hello,

    Now there is something close to this, setting a public Boolean to False, not a variable in a method.

    Add this class to a project (also available on NuGet packaged with a connection class). For demonstration let's attempt to read a file using the following class.  Note the inherit BaseExceptionProperties, this contains mHasException and mLastException.

    Public Class FileOperations
        Inherits BaseExceptionProperties
        Public Function ReadFileWithBaseExceptionProperties(ByVal fileName As String) As List(Of String)
            mHasException = False
            Dim lines = New List(Of String)()
                lines = File.ReadAllLines(fileName).ToList()
            Catch e As Exception
                mHasException = True
                mLastException = e
            End Try
            Return lines
        End Function
    End Class

    We would call it as shown below

    Dim fileOps As New FileOperations
    Dim lines As List(Of String) = fileOps.ReadFileWithBaseExceptionProperties("SomeTextFile.txt")
    If fileOps.IsSuccessFul Then
        ' use lines
    End If

    If IsSuccessful is true this means we can use the List will if IsSuccessFul is false the operation failed and we would use LastExceptionMessage to see what happened.

    Note, mHasException is set to False at the start in the event another method is call with the same instance of this class.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, February 14, 2019 3:11 AM