dimanche 7 mars 2021

END not functioning properly in long if-statement [Visual Basic]

I have been trying to create a menu in visual basic and I have been coming across a small problem. All my options work for now except when I try selecting the ‘exit program’ option. When I input 5, the program prints “goodbye” and then stays there, the terminal doesn’t close.

I am wondering if it doesn’t work properly because I have put it into a long if-statement.

I tried creating a separate if-statement for the ‘exit program’ option but when I run my code it simply ignores it as the longer if-statement takes priority.

Any help would be appreciated!

Dim useroption As Integer

Console.WriteLine("Welcome, please select any of the options below:")

Console.WriteLine(linebreak)

Console.WriteLine("1 - Accuracy Option")

Console.WriteLine("2 - Quadratic Equation")

Console.WriteLine("3 - Protein Sequence Segmentation")

Console.WriteLine("4 - Monte-carlo Integration of a Function")

Console.WriteLine("5 - Exit Program")

Console.WriteLine(linebreak)

useroption = Val(Console.ReadLine())



    If useroption = 1 Then

        Console.WriteLine("You have selected: Accuracy Option")
        'then call up function that deals with accuracy'



    ElseIf useroption = 2 Then

        Console.WriteLine("You have selected: Quadratic Equation")
        'calls up quadratic equatipn function'


    ElseIf useroption = 3 Then

        Console.WriteLine("You have selected: Protein Sequence Segmentation")
        'calls up protein function'


    ElseIf useroption = 4 Then

        Console.WriteLine("You have selected: Monte-carlo Integration of a Function")
        'calls up monte-carlo function'


    ElseIf useroption = 5 Then

        Console.WriteLine("Goodbye")
        End 'not working, it just prints goodbye and nothing happens to the program'


    Else

        Console.WriteLine("Invalid option, please try again")
        Console.WriteLine(" ")
        Main() 'runs from the top again as the user has inputted an invalid option'

    End If

Aucun commentaire:

Enregistrer un commentaire