How do I pass parameters from DOS to the VB.NET application ? I've tried but nothnig gets displayed in the VB.NET app when I try to interrogate Command() stored in a string. like start Add.application 1,2 etc......
Nothing seems to get passed to the VB App
Thanks
Dave
18 Feb 2013
I haven't encountered problems with this using "old" visbasic. You might post your code (simplified toward the issue at hand). Not sure about .net...
Attribute vb_name = "test"
sub main
x=command
msgbox x
end sub
delivers the goods using my version.
Hmm. I'm using VB.NET 2008 I got the code of YouTube : http://www.youtube.com/watch?v=r7V2... However it was written for a VB.NET to VB.NET parameter transfer. I thought it might work by calling the VB.NET App from DOS along with passing command line arguments from DOS, however no argument data seems to get displayed in the VB app.
Thus the VB app starts ok, just that no command line parameters / argument data get displayed after it starts.
APP CODE BELOW
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
''MsgBox(Command())
MsgBox(Command)Try
Dim ReceivedText As String = Command()
'MsgBox(ReceivedText)
Me.Label1.Text = ReceivedText
Me.Label1.Refresh()Catch ex As Exception
MsgBox("Error: " & (ex.Message))
End Try
End Sub
mebbe try it without the parens ():
x=command
msgbox xI'm quite lame when it comes to .net.
Thanks, VB.NET puts () on it, even if you type it without, so Command() seems to be correct. Just not picking up the command arguments when calling the VB app from DOS.
Consider the following (command line) application: Option Infer On : Option Strict On Module Module1 Sub Main() Dim args = My.Application.CommandLineArgs.ToArray() If args.Length = 0 Then Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location, _ "arg1 arg2 arg3 arg4") Exit Sub End If Console.WriteLine(Join(args, vbNewLine)) Console.Write("Press any key to exit . . . ") Console.ReadKey(True) End Sub End Module
Thanks, but what does this app do ? Doesn't seem to work for me in VB.NET 2008 i.e. the program crashes.
"Says cannot read keys when either application does not have a console or when console input has been redirected from a file. Try Console Read."
Ahh I had to make a console application to get it to work. Seems to work ok now. Never used a VB console app before. I guess that means I will need to have two applications.
1. A console application to be called from DOS with arguments
2. My regular VB.NET application that I presume this console app will then load with the same arguments.
Does that sound right ?
Seems a bit convolouted to have to have this extra appliaiton, but if it works then it works I guess.
All that said, it's still not displaying the argument data when called from DOS with arguments. Instead it's just displaying the variable names
arg1
arg2
arg3
arg4
I guess that means I will need to have two applications.
You don't. I prefer to do sample code as a console application, because its code fits in a single file. You can easily convert it to a WinForms application. The underlying logic does not change.Option Infer On : Option Strict On Public Class Form1 Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles Me.Shown Dim args = My.Application.CommandLineArgs.ToArray() If args.Length = 0 Then Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location, _ "arg1 arg2 arg3 arg4") Close() End If MessageBox.Show(Join(args, vbNewLine)) End Sub End Class
EDIT: If it doesn't work, it's a problem on your end. I've tested it, and it works.Mon 2013.02.18 19.33.32++ M:\bin\Debug>type \Form1.vb Option Infer On : Option Strict On Public Class Form1 Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles Me.Shown Dim args = My.Application.CommandLineArgs.ToArray() If args.Length = 0 Then Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location, _ "arg1 arg2 arg3 arg4") Close() Else MessageBox.Show(Join(args, vbNewLine)) End If End Sub End Class Mon 2013.02.18 19.33.46++ M:\bin\Debug>WindowsApplication1 123 456 789Produces:123 456 789
OK thanks. I've tried both versions and although they run without error, they don't seem to display the argument data though. i.e. if I run it from DOS with arguments. For example DOS command prompt C:> MyApp.application zzz xxx ccc vvv
The application starts up ok, however just displays the argument variable names and not the actual data.
Any idea why ?
What format should I use when passing the arguments from DOS ?
Well, it could be a few things, but I'd have to see exactly what you're typing. Try copy/pasting your command line and we'll run through the usual suspects. Also, it's not DOS. DOS is dead. It died 13 - 18 years ago. WinNT has a Command Prompt. CMD is also a valid choice.
Yep sorry from CMD prompt. Under Windows 7 C:\TEST>Add2.application zzz,mxx,xxx,ccc
Also tried without commas
C:\TEST>Add2.application zzz mxx xxx ccc
The output I get from both is the same. i.e. as follows;
arg1
arg2
arg3
arg4
Don't invoke the .application file. Invoke the .exe file. Giving up command line arguments is one of the trade offs of using ClickOnce.
Ahh I see. OK it works fine. Thanks for that advice. I think I need to do a VB.NET course. Anyway I found the .exe version and it worked ok. Your help is much appreciated.
