Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[VB] Basic Menu System [CONSOLE]

Hello Everyone,

I have decided to throw this code together so you can use it in your own console programs. The menu is VERY basic and can be worked to look a lot better.

The menu system works by having a list of options which can be selected with a number. After you have typed in the number and pressed enter it is then saved to a variable which is then called to display the option chosen.
Like I said it is was a VERY basic project and can be improved if you wish.

Screenshots of It Working:

Default Page:
[Image: an4PgWu.png]

For Option 1 - 3:
[Image: pgbX78r.png]

ChangeLog:
[Image: bJzTawQ.png]

Authors:
[Image: 9024YLQ.png]


The Code:
Code
Module Module1
    Dim choice As Integer
    Dim backtomenu As String
    Sub Main()
        'Menu System Coded By PatientZero

        Console.ForegroundColor = ConsoleColor.Red
        Console.WriteLine("--------------------------------")
        Console.ForegroundColor = ConsoleColor.DarkGreen
        Console.WriteLine("Basic Menu System By PatientZero")
        Console.ForegroundColor = ConsoleColor.Red
        Console.WriteLine("--------------------------------")
        Console.ForegroundColor = ConsoleColor.DarkGreen
        Console.WriteLine("1> OPTION 1")
        Console.WriteLine("2> OPTION 2")
        Console.WriteLine("3> OPTION 3")
        Console.WriteLine("4> View ChangeLog")
        Console.WriteLine("5> View Authors")
        Console.WriteLine("6> Exit")
        Console.ForegroundColor = ConsoleColor.Red
        Console.WriteLine("--------------------------------")
        Console.ForegroundColor = ConsoleColor.DarkGreen
        choice = Console.ReadLine()

        Console.WriteLine()

        Select Case choice
            Case Is = 1
                Option1()
            Case Is = 2
                Option2()
            Case Is = 3
                Option3()
            Case Is = 4
                ChangeLog()
            Case Is = 5
                Authors()
            Case Is = 6
                MenuExit()
        End Select
    End Sub

    Sub Option1()
        Console.Clear()
        Console.ForegroundColor = ConsoleColor.Green
        Console.WriteLine("Temporary Placeholder For Option 1")
        Console.WriteLine()
        Console.WriteLine("To Return To Menu Press M, Or To Exit Press ENTER")
        backtomenu = Console.ReadLine()
        MenuReturn()
    End Sub

    Sub Option2()
        Console.Clear()
        Console.ForegroundColor = ConsoleColor.Green
        Console.WriteLine("Temporary Placeholder For Option 2")
        Console.WriteLine()
        Console.WriteLine("To Return To Menu Press M, Or To Exit Press ENTER")
        backtomenu = Console.ReadLine()
        MenuReturn()
    End Sub

    Sub Option3()
        Console.Clear()
        Console.ForegroundColor = ConsoleColor.Green
        Console.WriteLine("Temporary Placeholder For Option 3")
        Console.WriteLine()
        Console.WriteLine("To Return To Menu Press M, Or To Exit Press ENTER")
        backtomenu = Console.ReadLine()
        MenuReturn()
    End Sub

    Sub ChangeLog()
        Console.Clear()
        Console.WriteLine("~~~~~ CHANGELOG ~~~~~")
        Console.ForegroundColor = ConsoleColor.Green
        Console.WriteLine("[+] Version 1.0 Of Basic Menu System")
        Console.WriteLine()
        Console.WriteLine("To Return To Menu Press M, Or To Exit Press ENTER")
        backtomenu = Console.ReadLine()
        MenuReturn()
    End Sub

    Sub Authors()
        Console.Clear()
        Console.ForegroundColor = ConsoleColor.Green
        Console.WriteLine("Program Name: Basic Menu System")
        Console.WriteLine("Program Author: PatientZero")
        Console.WriteLine("Last Updated: 03/10/2014")
        Console.WriteLine()
        Console.WriteLine("To Return To Menu Press M, Or To Exit Press ENTER")
        backtomenu = Console.ReadLine()
        MenuReturn()
    End Sub

    Sub MenuReturn()
        If backtomenu = "M" Then
            Console.Clear()
            Main()
        Else
            MenuExit()
        End If
    End Sub
    Sub MenuExit()
        Console.Clear()
        Console.ForegroundColor = ConsoleColor.Green
        Console.WriteLine("Thank You For Using Our Program")
        Console.WriteLine("Basic Menu System Coded By PatientZero")
        Console.WriteLine()
        Console.WriteLine("Please Press ENTER To Confirm Exit")
        Console.ReadLine()
    End Sub

End Module
Code
choice = Console.ReadLine()

This does not make sense to me, you waiting for a single key input not a line.

Now once you change that to Char you can also change this:

Code
Select Case char
   Case "1"c : do stuff....
End Select

- B
(Oct 3, 2014 09:17 AM)TheBarret Wrote:  
Code
choice = Console.ReadLine()

This does not make sense to me, you waiting for a single key input not a line.

Now once you change that to Char you can also change this:

Code
Select Case char
   Case "1"c : do stuff....
End Select

- B

That is very true indeed,
This is just the way I have decided to program in VB Console since Day 1.
(Oct 3, 2014 09:17 AM)TheBarret Wrote:  
Code
choice = Console.ReadLine()

This does not make sense to me, you waiting for a single key input not a line.

Now once you change that to Char you can also change this:

Code
Select Case char
   Case "1"c : do stuff....
End Select

- B

How is he waiting for a "single key"? He's not using .ReadKey(), .ReadLine() is different.

ReadLine: http://msdn.microsoft.com/en-us/library/....110).aspx
ReadKey: http://msdn.microsoft.com/en-us/library/....110).aspx
шкідливе ПО для ентузіастів

Jabber: [email protected]
[email protected]

(Oct 3, 2014 05:41 PM)Zettabit Wrote:  How is he waiting for a "single key"? He's not using .ReadKey(), .ReadLine() is different.

ReadLine: http://msdn.microsoft.com/en-us/library/....110).aspx
ReadKey: http://msdn.microsoft.com/en-us/library/....110).aspx

Thats what hes saying.
Hes asking why wait for a return, instead why not use .ReadKey().


See OP's code:
choice = Console.ReadLine()

TheBarret says to use
Console.Readkey().

Simple.
(Oct 3, 2014 05:55 PM)xMoD Wrote:  Thats what hes saying.
Hes asking why wait for a return, instead why not use .ReadKey().


See OP's code:
choice = Console.ReadLine()

TheBarret says to use
Console.Readkey().

Simple.

Ah, I misinterpreted his statement, my bad. It's been a long night...
шкідливе ПО для ентузіастів

Jabber: [email protected]
[email protected]

Code
Sub Option2()
      Console.Clear()
      Console.ForegroundColor = ConsoleColor.Green
      Console.WriteLine("Temporary Placeholder For Option 2")
      Console.WriteLine()
      Console.WriteLine("To Return To Menu Press M, Or To Exit Press ENTER")
      backtomenu = Console.ReadLine()
      MenuReturn()
    End Sub

This is useless, use a function.
[Image: vjPWhyy.gif]
(Oct 3, 2014 09:53 PM)$lick Wrote:  This is useless, use a function.

The entire thing is useless mate, not just that sub. 😏
(Oct 3, 2014 05:41 PM)Zettabit Wrote:  How is he waiting for a "single key"? He's not using .ReadKey(), .ReadLine() is different.

ReadLine: http://msdn.microsoft.com/en-us/library/....110).aspx
ReadKey: http://msdn.microsoft.com/en-us/library/....110).aspx

I dont think you understand what theire made for.

let me rephrase that; He is waiting for a single char, wich the Console.ReadKey() is doing just that. he is using the Readline().
Interesting, wouldnt it be esier to code it in batch?
(Oct 4, 2014 04:56 AM)420 Blaze It Wrote:  Interesting, wouldnt it be esier to code it in batch?

Maybe,
I just prefer VB and C++ than the rest 🤝


(Oct 4, 2014 04:55 AM)TheBarret Wrote:  I dont think you understand what theire made for.

let me rephrase that; He is waiting for a single char, wich the Console.ReadKey() is doing just that. he is using the Readline().

Oh yes,
I will use a ReadKey() instead next time :)
Thanks for the feedback :D
(Oct 4, 2014 04:56 AM)420 Blaze It Wrote:  Interesting, wouldnt it be esier to code it in batch?

Well for 1, batch isn't a programming language its a script language
and 2, batch is so limited because its not indented for for anything apart from core system functions.
(Oct 5, 2014 09:31 AM)TheVBNetwork Wrote:  Well for 1, batch isn't a programming language its a script language
and 2, batch is so limited because its not indented for for anything apart from core system functions.

Hmmz well im about to raise my current project to a new level wich involves a script engine i development myself where i want to add the ability to create custom forms and what not.

its pretty long project im working on but it resembles a syntax that is derived or better said influenced from C#, VB and Ruby.

If your intrested, pm me about it ^^


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Shell] by Emre_Sep 1, 2019 07:17 PM 0 134 Sep 1, 2019 07:17 PM
Last Post: Emre_
[Python] by jmcatena91Feb 12, 2018 11:34 AM 5 210 Feb 12, 2018 11:34 AM
Last Post: vorticalbox
[C#] by OdusSep 8, 2016 02:10 PM 29 2,509 Sep 8, 2016 02:10 PM
Last Post: 0xDEAD10CC