CryoEnix Posted January 20, 2005 Posted January 20, 2005 Hey peeps, does anybody know how to retrieve the parameters passed to the compiled exe at runtime? In Java you get an array of strings right in front of you (args[]), so how is this done in VB.NET? Thanks Quote Chaos is merely logic beyond human comprehension
BlackStone Posted January 20, 2005 Posted January 20, 2005 Just add an array of strings as the parameter of the Main method. Sub Main([b]ByVal args() As String[/b]) .... End Sub Quote "For every complex problem, there is a solution that is simple, neat, and wrong." - H. L. Mencken
CryoEnix Posted January 20, 2005 Author Posted January 20, 2005 Just add an array of strings as the parameter of the Main method. Sub Main([b]ByVal args() As String[/b]) .... End Sub ...That does seem a little too easy... *runs back to check* By the 'Main' sub, are you referring to form_load? There are already two parameters in there by default: (ByVal sender As System.Object, ByVal e As System.EventArgs) Quote Chaos is merely logic beyond human comprehension
BlackStone Posted January 21, 2005 Posted January 21, 2005 In VB, you don't need a special "Main" method in a windows app (I think it generates one behind the scenes). So you can either add one to your form: Public Shared Sub Main(ByVal args() As String) ' Starts the app with whatever form you want: Application.Run(New Form1()) End Sub or you can use Environment.CommandLine. PS: Just in case this wasn't clear, the form_Load() is an event which is called when the form loads, and it is not the "Main" subroutine, therefore you cannot add the parameter args(). Quote "For every complex problem, there is a solution that is simple, neat, and wrong." - H. L. Mencken
donnacha Posted January 21, 2005 Posted January 21, 2005 The way to do it is using Environment.GetCommandLineArgs Environment.GetCommandLineArgs.Length is the count of parameters present Environment.GetCommandLineArgs(n) is the nth comand line arg That is all you need Quote Hamlet
CryoEnix Posted January 21, 2005 Author Posted January 21, 2005 Cheers guys, You've both been a great help. Additionally: Blackstone, The Main method you're referring to - does it run on startup like the one in Java, or does it need to be called? Quote Chaos is merely logic beyond human comprehension
BlackStone Posted January 21, 2005 Posted January 21, 2005 It runs on startup (in a Windows App, you have to change the startup object to "sub Main()" ) Quote "For every complex problem, there is a solution that is simple, neat, and wrong." - H. L. Mencken
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.