Interaction.Command 方法

定義

傳回用來啟動 Visual Basic 之命令列的引數部分,或是使用 Visual Basic 所開發的可執行程式。 My 功能提供了比 Command 函式更強大的產能和效能。 如需詳細資訊,請參閱CommandLineArgs

public:
 static System::String ^ Command();
public static string Command ();
static member Command : unit -> string
Public Function Command () As String

傳回

用來啟動 Visual Basic 之命令列的引數部分,或是使用 Visual Basic 所開發的可執行程式。

My 功能提供了比 Command 函式更強大的產能和效能。 如需詳細資訊,請參閱CommandLineArgs

範例

這個範例會使用函 Command 式傳回物件中包含數位的命令行自變數。

Function GetCommandLineArgs() As String()
    ' Declare variables.
    Dim separators As String = " "
    Dim commands As String = Microsoft.VisualBasic.Interaction.Command()
    Dim args() As String = commands.Split(separators.ToCharArray)
    Return args
End Function

備註

傳回自變數之後,您可以搜尋常見的分隔符,例如空格、向後斜線、連字元或引號,以分割或搜尋個別參數的字串。

針對使用 Visual Basic 開發並編譯為 .exe 檔案的應用程式,此 Command 函式會傳回在命令行上應用程式名稱後面出現的任何自變數: MyApp(cmdlineargs)

適用於

另請參閱