Converting to Console app.

jasgiv1122

Member
Joined
Jul 31, 2009
Messages
6
Programming Experience
1-3
ooooh, my first of many vb.net questions... What a glorious day.

I've done a lot of research on this, but I need a fresh take on the situation so I can actually grasp what I need to do. I have a fully functional VB program with GUI and everything. However, for it to be effective - it needs to run without user input.

I have heard that you can use certain functions, like putting a line or 2 in startup to look for an argument, but I can't get anything to work (I wasn't able to use functions established in Main

I want to make it so when I put in something along the lines of -b after the program in a cmd prompt, it will launch a console application and do a specific task defined in Main... If this is impossible, then I'd like to just edit the application in VB Express 2008 and try to make it a console application instead of a windows app. Thanks for any help. (My apologies if this is not the correct forum)
 
Here is a simple tutorial for you
Command Line Args

Basically your app will look like
VB.NET:
Sub Main(ByVal args As String())
    For Each arg As String In args
        if arg = "-b" then
            'Preform Tasks
        end if
    Next arg 
    Console.ReadLine()
End Sub

If your application's name was 'MyApp.exe'. Then you would run 'MyApp.exe -a'
 
Thanks for the response...

Does this go in the application.startup area? Or am I just pasting this in my frmMain? Sorry if this is a stupid question!

-Jason :cool:
 
In both WinForms and Console apps you can always get the commandline args using Environment.GetCommandLineArgs() which returns a 1 dimension array of the args, the first one (index: 0) is always the app's full path and name
 
I'm still very new to Visual Basic and .net... I've read in places that I'm supposed to be putting these commands in application.events (startup). Can someone guide me at this part? Do I create a new module to do this? Thanks! Sorry for the low level of knowledge I possess on the topic.
 
For ease of use I'm lazy and I just put it in the form's load event for WinForms apps and for console app's I just put it at the top part of Sub Main()
 
I must apologize again... if I wanted it to be like the other response this thread got, what would the syntax be? I'm brand new to VB, so I'm even having difficulty finding the load.event area... Any help you can offer, is greatly appreciated!

Sub Main(ByVal args As String())
For Each arg As String In args
if arg = "-b" then
'Perform Tasks
end if
Next arg
Console.ReadLine()
End Sub

I know this much

Console.WriteLine()
' Invoke this sample with an arbitrary set of command line arguments.
Dim arguments As [String]() = Environment.GetCommandLineArgs()
Console.WriteLine("GetCommandLineArgs: {0}", [String].Join(", ", arguments))

But I'm running into issues with placing in there what I want... I want it to Send("Download Term", "00", "XDLD", "") if there is a -b switch. I'd like it to do this instead of open the GUI... just do the console command instead. Thanks
 
You're combining two ways of doing the same thing, all you gotta do is pick one:
VB.NET:
Sub Main(ByVal args() As String)
    For Counter As Integer = 0I To args.GetUpperBound(0I)
        Select Case args(Counter).ToLower
            Case "-b"
                'Set Vars
            Case "download term"
                'Set Vars
        End Select
    Next Counter
    'Rest of program
End Sub
or
VB.NET:
Sub Main()
    Dim args() As String = Environment.GetCommandLineArgs()
    For Counter As Integer = 0I To args.GetUpperBound(0I)
        Select Case args(Counter).ToLower
            Case "-b"
                'Set Vars
            Case "download term"
                'Set Vars
        End Select
    Next Counter
    'Rest of program
End Sub
 
Back
Top