vb.NET下获取命令行参数的方法
命令行参数允许用户或其他程序向程序传送启动信息。例如:程序名为test.exe,可以运行以下命令:
test.exe /help
在VB6中,可以使用Command属性读取它。在Vb.NET中,它已替换为System.Environment.GetCommandLineArgs函数,该函数返回一组传送的启动参数。
代码如下:
Dim myArg() As String, iCount As Integer
myArg = System.Environment.GetCommandLineArgs
For iCount = 0 To UBound(myArg)
TextBox1.Text = TextBox1.Text & "|" & myArg(iCount).ToString
Next
我的用法如下:
Imports System.Windows.forms
Module Module1
Sub Main()
Dim myArg() As String
Dim icount As Integer
myArg = System.Environment.GetCommandLineArgs
For icount = 0 To UBound(myArg)
MessageBox.Show(myArg(icount).ToString)
Next
End Sub
End Module
运行通过
没有评论:
发表评论