Print a line in DOS COnsole through VB6

Posted on 2004-11-17
Medium Priority
Last Modified: 2013-12-25
Hello All
I am Akthar and I am new to this form, I have a question in VB6 application,.
I ave created an application in VB that can run in both GUI and dos mode. in dos mode it will run like a batch process. Now I am stuck in returning a value ina dos mode.
What I mean is if my application returns an error I need to capture it and print in to the active DOS console.
Can some one please help me with this situation./
Question by:AKthar_mailme
  • 3
  • 2
LVL 28

Expert Comment

ID: 12610462
"If a Visual Basic application is started from a console application, the operating system automatically detaches it from the console, preventing the Visual Basic application from interacting with it."

The above is from this link:


LVL 28

Expert Comment

ID: 12610478
LVL 86

Accepted Solution

Mike Tomlinson earned 2000 total points
ID: 12611513
It IS possible to make your VB6 app echo back to the same DOS console from which it was run.

I have successfully used the technique described here:

I created a new project and added a reference to the Microsoft Scripting Runtime.  Then I added a Module with the following code:

    Sub Main()
        Dim fso As New FileSystemObject
        fso.GetStandardStream(StdOut).Write ("Hello World")
    End Sub

From the Project Properties, I set the startup object to be Sub Main and then removed Form1 from the project.  I compiled the application as VBConsole.exe in the following folder:

    C:\Program Files\Microsoft Visual Studio\VC98\Bin

Then I copied this file into the Bin folder as well:

    C:\Program Files\Microsoft Visual Studio\VB98\MSPDB60.DLL

Next I used the EditBin utility as described in the PDF document and ran VBConsole.  "Hello World" did echo back successfully to the DOS console from which my app was run.  Here is the text from my Console window showing EditBin being used and then VBConsole.Exe being run:

C:\PROGRA~1\MICROS~6\VC98\BIN>editbin /subsystem:console vbconsole.exe
Microsoft (R) COFF Binary File Editor Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

Hello World
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12627048
From my Feedback:

Thanks a lot for your help, I did went with this approch but I got an error in this, it says RunTime Error '2147024890(80070006) Method '~' od Object '~' failed
what shall I do, at his point since I am new to Vb and I still have a hude distance to cover.
Thanks a lot again.

Make sure you have a reference to the Microsoft Scripting Runtime added to your project by selecting Project --> References from the menu.

I am running VB6 (SP6) in WinXP Pro with all updates.

LVL 28

Expert Comment

ID: 12948405
Dan, I think this one should go to Idle Mind.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question