在子例程中退出选择案例

时间:2019-03-09 16:41:16

标签: vb.net select-case

我有一个问题,

在我的主要标签中,我执行的功能/子例程彼此遵循。然后,我的第三个子例程之一包含一个选择用例,对于输入5,我希望它继续下一个子例程,但是我不确定如何执行此操作。

Sub Main()

    Task723()
    Task724()
    Task731()

End Sub

Sub Task723()
    Dim x0 = -20 ' Initial values assumed
    Dim ch As Integer
    ch = 5
    While ch <> 0
Line2:
        Console.WriteLine(vbLf & "(1)option1"
        Console.WriteLine(vbLf & "(2)option2")
        Console.WriteLine(vbLf & "(3)option3")
        Console.WriteLine(vbLf & "(4)option4")
        Console.WriteLine(vbLf & "(5)to go next")
        Console.Write(vbLf & "Enter Your Choice :")
        ch = Integer.Parse(Console.ReadLine())
        Select Case ch
            Case 1
                option1(x0)
                Console.WriteLine(vbLf & "Press Any Key To Continue...")
                Console.ReadLine()
                Console.Clear()
            Case 2
                option2(x0)
                Console.WriteLine(vbLf & "Press Any Key To Continue...")
                Console.ReadLine()
                Console.Clear()
            Case 3
                option3(x0)
                Console.WriteLine(vbLf & "Press Any Key To Continue...")
                Console.ReadLine()
                Console.Clear()
            Case 4
                option4(x0)
                Console.WriteLine(vbLf & "Press Any Key To Continue...")
                Console.ReadLine()
                Console.Clear()
            Case 5
                Console.Clear()
                GoTo Line4

            Case Else
                Console.Clear()
                Console.WriteLine(vbLf & "Invalid Input, Please Try Again")
                GoTo Line2


        End Select
Line4:
    End While
End Sub

1 个答案:

答案 0 :(得分:0)

您只想将ch设置为0并退出随后的While ch <> 0检查

            Case 5
                Console.Clear()
                ch = 0

顺便说一句,您不需要Line2:Line4:以及那些GoTo Line2GoTo Line4