There are 4 important things to consider.
- Command$() and Environ$()
First two simply VB commands. Command$ is used to read command line arguments and Environ$ is used to read environment variables.
- Standard I/O
Add Microsoft Scripting Runtime from References. See following example for usage.Code: Select all
'Requires a reference to Microsoft Scripting Runtime. Sub Main() Dim FSO As New Scripting.FileSystemObject Dim sin As Scripting.TextStream Dim sout As Scripting.TextStream Dim strWord As String Set sin = FSO.GetStandardStream(StdIn) Set sout = FSO.GetStandardStream(StdOut) sout.WriteLine "Hello!" sout.WriteLine "What's the word?" strWord = sin.ReadLine() sout.WriteLine "So, the word is " & strWord Set sout = Nothing Set sin = Nothing End Sub
- Return codes
To exit and pass a return code you need another API call:Code: Select all
Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
- Link as Console App
Use following command to Re-Link the VB EXE as a Console Application. LINK.EXE comes with VB6.Code: Select all
LINK.EXE /EDIT /SUBSYSTEM:CONSOLE YourVBEXEName.EXE