VB Question: Creating a zero GUI commandline app

Status
Not open for further replies.

svdsinner

Ars Legatus Legionis
15,152
Subscriptor
OK, I'm not a VB guy, but the VB guy that works for me is stumped on the concept of using VB to manipulate some office apps via a command-line app that accepts command line parameters and returns command-line output.

He has the app done running with a GUI and returning the info to a GUI, but has no idea how to convert it into a command line app that take the 2 arguments (a filename and SQL statement, both strings) and output to the command line either "Done" or "Error". (All his previous apps have all been GUI)

What can I tell him to do to get unstuck?
 
Unless I misread your post, that's a very easy thing to do. You simply create a module, call it whatever you want, and create a Sub Main(). Specify Sub Main() as the startup object in the project properties. Output to the terminal can be done via the Print statement, and arguments to the application are received through the Command$ variable.

Something like this should work:

code:<HR>
Code:
Sub Main()
    Dim Args() as String, X as integer<P>    Args = Split(Command$)<P>    For X = 0 to UBound(Args)
       Print "Arguemnt " & X & " - " & Args(X) & vbCrLf
    Next<P>    Print "All done. Bye."
End Sub

Haven't written VB6 code in a while...give it a try.

Edit: Okay, maybe not...I'll look for some more info.

[This message was edited by PreciousRoy on January 31, 2002 at 18:32.]
 

Wraith

Ars Tribunus Militum
1,712
Googling gives this
http://www.vb-world.net/api/console/
Which leads you through creating a console app in VB.

If you want a completely formless app all you have to do is:
open a new project,
add a module,
remove the form,
place a procedure called main() in the module

main() becomes the default procedure and the pallication starts for there instead of form_load() . for example put this in the module

code:<HR>
Code:
 Option Explicit<P>Private Sub main()
MsgBox Command, vbOKOnly, "formless app commandline params are."
End
End Sub

try that as described above and give it some commandline parameters, they should turn up in the messagebox.
 

DaleDBeast

Wise, Aged Ars Veteran
172
If you run your VB app from a console window, all that does is cause Windows to execute the VB runtimes, passing the name of your VB app and its parameters . Your VB app then executes as a windowed process even though there may be no form in VB app itself.

The solution is to get a handle to the console where the VB app was started, then work with events in that console. You must use the API.

Wraith's link explains it all.
 
Status
Not open for further replies.