如何在vb .net中将参数作为命令行参数传递给exe,并举例说明 [英] How to pass parameters to an exe as command line parameters in vb .net ,explain with example

查看:153
本文介绍了如何在vb .net中将参数作为命令行参数传递给exe,并举例说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行时必须发送一些参数吗?

At runtime a have to send some parameters?

推荐答案

命令行参数可以通过以下两种方式之一进行处理:
1)您可以在您的Main函数中访问.
2)您可以通过Application对象在Windows窗体类中访问它们.

如果这是一个控制台应用程序,则使用第一个,否则使用第二个.

对于控制台应用程序,找到您的Main函数(它应该在您创建的第一个文件中):
Command line parameters can be handled in one of two ways:
1) You can access then in your Main function.
2) You can access them in your windows forms classes via the Application object.

If this is a console app, then use the first, otherwise use the second.

For console apps, find your Main function (it should be in the first file you created):
Sub Main(Byval args() As String)
   Dim data As String = args(0)
   Console.Writeline("Argument: {0}", data)
   Console.Write("Press Enter to exit")
   Console.Read()
End Sub



对于winforms,您所需要做的就是访问Application对象:



For winforms, all you need to do is access Application object:

For Each arg As String In My.Application.CommandLineArgs
    Console.WriteLine(arg);
Next


这篇关于如何在vb .net中将参数作为命令行参数传递给exe,并举例说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆