命令列提示原型
Module MainPrompt
Public Const PromptSymbol As String = "TLA > "
Public Const ApplicationTitle As String = GetType(Project.BaseClass).Assembly.FullName
REM Or you can use a custom string
REM Public Const ApplicationTitle As String = "Short name of the application"
Sub Main()
Dim Statement As String
Dim BrokenDownStatement As String()
Dim Command As String
Dim Args As String()
Dim Result As String
Console.ForegroundColor = ConsoleColor.Cyan
Console.Title = ApplicationTitle & " command line console"
Console.WriteLine("Welcome to " & ApplicationTitle & "console frontend")
Console.WriteLine("This package is version " & GetType(Project.BaseClass).Assembly.GetName().Version.ToString)
Console.WriteLine()
Console.Write(PromptSymbol)
Do While True
Statement = Console.ReadLine()
BrokenDownStatement = Statement.Split(" ")
ReDim Args(BrokenDownStatement.Length - 1)
Command = BrokenDownStatement(0)
For i = 1 To BrokenDownStatement.Length - 1
Args(i - 1) = BrokenDownStatement(i)
Next
Select Case Command.ToLower
Case "example"
Result = DoSomething(Example)
Case "exit", "quit"
Exit Do
Case "ver"
Result = "This package is version " & GetType(Project.BaseClass).Assembly.GetName().Version.ToString
Case Else
Result = "Command not acknowldged: -" & Command & "-"
End Select
Console.WriteLine(" " & Result)
Console.Write(PromptSymbol)
Loop
Console.WriteLine("I am exiting, time is " & DateTime.Now.ToString("u"))
Console.WriteLine("Goodbye")
Environment.Exit(0)
End Sub
End Module
該原型生成一個基本的命令列直譯器。
它會自動獲取應用程式名稱和版本以與使用者進行通訊。對於每個輸入行,它識別命令和任意引數列表,所有引數都用空格分隔。
作為一個基本示例,此程式碼瞭解 ver , quit 和 exit 命令。
引數 Project.BaseClass 是專案的一個類,其中設定了程式集詳細資訊。