Command 函数
更新:2007 年 11 月
返回用于启动 Visual Basic 或使用 Visual Basic 开发的可执行程序的命令行的参数部分。
My 功能可以提供比 Command 函数更高的效率和更好的性能。有关更多信息,请参见 My.Application.CommandLineArgs 属性。
Public Function Command() As String
备注
参数返回后,您可以搜索常用分隔符(如空格、反斜杠、正斜杠、连字符或引号)断开或搜索单个参数的字符串。
对于用 Visual Basic 开发的且编译为 .exe 文件的应用程序,Command 函数返回在命令行中出现于应用程序名称后的任何参数,其格式为:MyApp(cmdlineargs)。
示例
此示例使用 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
要求
**模块:**Interaction
**程序集:**Visual Basic 运行库(在 Microsoft.VisualBasic.dll 中)
请参见
概念
“Hello, World”的 Visual Basic 版本
参考
Environment.GetCommandLineArgs
My.Application.CommandLineArgs 属性