原文地址:http://www.vbdotnetheaven.com/UploadFile/pragati2478/HowtoPassParameterinEXE04052006084011AM/HowtoPassParameterinEXE.aspx
作者:April 05, 2006
有时开发人员需要从一个exe中调用另一个exe。当调用exe是可能是需要传递参数的。
用下面的代码在全局模块中建立一个用来被调用的exe。设置启动项为Submain()函数。
在例子中有两个参数是通过exe传递过来的。参数是以” ”分割而被传递的。
Imports System.Windows.Forms
Module Module1
Public Sub main()
Dim frm As New Form1
Dim str() As String
str = GetCommandLineArgs()
If (UBound(str) >= 0) Then
a = str(0).ToString
b = str(1).ToString
End If
Application.Run(frm)
End Sub
Function GetCommandLineArgs() As String()
' Declare variables.
Dim separators As String = " "
Dim commands As String = Microsoft.VisualBasic.Command()
Dim args() As String = commands.Split(separators.ToCharArray)
Return args
End Function
End Module
Module Module1
Public Sub main()
Dim frm As New Form1
Dim str() As String
str = GetCommandLineArgs()
If (UBound(str) >= 0) Then
a = str(0).ToString
b = str(1).ToString
End If
Application.Run(frm)
End Sub
Function GetCommandLineArgs() As String()
' Declare variables.
Dim separators As String = " "
Dim commands As String = Microsoft.VisualBasic.Command()
Dim args() As String = commands.Split(separators.ToCharArray)
Return args
End Function
End Module
将下面的代码写道调用的exe中,这里两个参数,”1”和”M”被传递过去了。
proc.Start(Application.StartupPath & "\Sambandh.exe", "1 M")