' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
﻿Imports System

Namespace E
    Public Enum StatusB
        OK
        [ERROR]
    End Enum
    Public Enum StatusA
        OK
        [ERROR]
    End Enum
    Public Class B
        Public Sub New()
            Console.WriteLine("B ctor")
        End Sub
        Public Function DoSomething() As StatusB
            Return StatusB.[ERROR]
        End Function
        Public Sub Close()
            Console.WriteLine("B Close")
        End Sub
    End Class
    Public Class A
        Public Sub New()
            Console.WriteLine("A ctor")
        End Sub
        Public Function DoSomething() As StatusA
            Return StatusA.OK
        End Function
        Public Function DoSomethingElse(ob As B) As StatusA
            Dim stat As StatusB = ob.DoSomething()
            If stat = StatusB.OK Then
                Return StatusA.OK
            Else
                Return StatusA.[ERROR]
            End If
        End Function
        Public Sub Close()
            Console.WriteLine("A Close")
        End Sub
    End Class
    Public Class Program
        Public Shared Sub Main(args As String())
            Dim oa As New A()
            Dim stat1 As StatusA = oa.DoSomething()
            If stat1 <> StatusA.OK Then
                Console.WriteLine("We have a problem")
                GoTo close_a
            End If
            Dim ob As New B()
            Dim stat2 As StatusA = oa.DoSomethingElse(ob)
            If stat2 <> StatusA.OK Then
                Console.WriteLine("We have a another problem")
                GoTo close_b
            End If
            Console.WriteLine("Everything OK")
        close_b:
            ob.Close()
        close_a:
            oa.Close()
        End Sub
    End Class
End Namespace
