将信息从VBA传递到VB.NET
我试图将一个字符串从VBA应用程序(通过MicroStation-CAD绘图工具运行)传递到VB.NET程序,但遇到了一些困难。我在这里找到了一些类似的线程,但我的线程似乎不想工作 问题的VBA部分在这里。这段代码来自另一个Stackoverflow线程,它问了一个与我是什么类似的问题将信息从VBA传递到VB.NET,vb.net,vba,Vb.net,Vba,我试图将一个字符串从VBA应用程序(通过MicroStation-CAD绘图工具运行)传递到VB.NET程序,但遇到了一些困难。我在这里找到了一些类似的线程,但我的线程似乎不想工作 问题的VBA部分在这里。这段代码来自另一个Stackoverflow线程,它问了一个与我是什么类似的问题 Dim strProgramName As String Dim strArgument As String strProgramName = HPDIR & "Utilitie
Dim strProgramName As String
Dim strArgument As String
strProgramName = HPDIR & "Utilities\HP_CheckForUpdates.exe"
strArgument = "/ver=" & vVersion(0)
Call Shell("""" & strProgramName & """ """ & strArgument & """", vbNormalFocus)
我的问题是如何让我的VB.NET程序阅读上述参数?
在另一个线程中,我找到了“Environment.GetCommandLineArgs”,但我的总是返回“System.String[]”
基本上,我所要做的就是从VBA中获取字符串并在VB.NET中显示它。我很高兴听到其他/更好的方法,而不是参数。以下是如何将命令行参数从一个vb程序发送到另一个vb程序 发送方模块:
Module Module_Sender
Sub Main()
Dim strCommand As String
strCommand = "CommandReciever.exe" + Space(1) + " ali"
Console.WriteLine("Sending shell command ... ")
Interaction.Shell(strCommand, AppWinStyle.NormalFocus)
End Sub
End Module
Module Module_Reciever
Sub Main()
Dim args() As String = System.Environment.GetCommandLineArgs()
If (args.Length > 0) Then
'display param And exit
Console.WriteLine("Program param = " + args(1))
Console.WriteLine("press enter key to exit ...")
Console.Read()
Return 'System.Environment.Exit(1);
Else
Console.WriteLine("Hey, Program id param expected ...")
End If
End Sub
End Module
接收器模块:
Module Module_Sender
Sub Main()
Dim strCommand As String
strCommand = "CommandReciever.exe" + Space(1) + " ali"
Console.WriteLine("Sending shell command ... ")
Interaction.Shell(strCommand, AppWinStyle.NormalFocus)
End Sub
End Module
Module Module_Reciever
Sub Main()
Dim args() As String = System.Environment.GetCommandLineArgs()
If (args.Length > 0) Then
'display param And exit
Console.WriteLine("Program param = " + args(1))
Console.WriteLine("press enter key to exit ...")
Console.Read()
Return 'System.Environment.Exit(1);
Else
Console.WriteLine("Hey, Program id param expected ...")
End If
End Sub
End Module
也许这个问题会帮助你谢谢你的链接。不幸的是,这对我没有帮助,因为当VB.NET程序加载时,“GetCommandLineArgs”总是空的。如果您在上面的链接中这样使用:
Sub Main(ByVal args()作为字符串)
那么您不需要您提到的任何东西,您在字符串数组args()中有命令行参数!它仍然一无所获。有没有其他/更好的方法来实现这一点?那么您有HP\u CheckForUpdates.exe
的源代码了吗?我建议首先使用命令行参数单独测试该程序。将VBA从等式中去掉,并确定您可以识别.Net中的命令行参数(它适用于其他所有人)。不要试图把一堆东西钉在一起,认为它会起作用——对每一件单独进行单元测试。从HP_CheckForUpdates.exe开始
您可以将发送方和接收方控制台应用程序放在同一文件夹中进行测试,然后运行发送方,它将调用接收方并显示从发送方收到的参数。