Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17



Posted on 1998-12-29
Medium Priority
Last Modified: 2010-05-03
As antiquated as this may sound there is a reason...  I have an EXE (created in VB5) that accepts command line arguments.  It's run in DOS full-screen.  I DO NOT want any output from this EXE to be put in a window (msgbox, output results on a form text box, etc) I want it to just simply display on the following line of the DOS window.  How would this be done?
Question by:davism
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +2

Expert Comment

ID: 1453083
You can write the program in QBasic or C (free compilers on the web), and then call the program from VB:

Dim r as long
r = shell("C:\path\program.exe", 1)


Expert Comment

ID: 1453084

Sorry lad, it can not be done.
8 years of service.


Author Comment

ID: 1453085
Writing the program in C then calling it from VB is not beneficial.  If I opt to take this route then I would leave VB out of the picture all together and just right it in C.  (There is no benefit of writing the program in C just so that VB can call it.  Unless, of course...I'm missing something.)

As for it NOT being able to be done...I'm not discounting that at all.  It's hard to believe that it can't be done but I also can't rule it out.  
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!


Expert Comment

ID: 1453086
Try this ..

1. Create an EXE which reads the command line (see  VB help on Command())
< In your project properties set the start up object as >
< Sub Main (). Remove all forms, create a standard      >
< module with your processing routines                  >
2. Perform your processing on the command line
3. Send the message/outputs to a text file

4. Create a batch file which the user executes and gives a command line parameter
5. in the batch file send the command line parameter to your EXE
6. Type the contents of the text file generated in 3. to the console screen via the batch file

 a bit involved but does the job.

LVL 13

Expert Comment

ID: 1453087
This is the function that you need.
Create a Standard exe and start using sub main.
Now use the following API function in your app.

Don't have a sample at this moment. But maybe it already helps you.

Author Comment

ID: 1453088
Mirkwood, do you know where I can get a sample of this code for VB?  Or if you can provide a sample for VB I'd be willing to increase the points.

Expert Comment

ID: 1453089
You're absolutely right about there being little/no point in writing a program in C, and then using VB to call it. If you are only familiar with VB coding, then there is a reason right there to not write the code in C. However, there are QBasic and PowerBasic compilers out there that will produce a DOS executable.

I am going to look into Mirkwood's WriteConsole API answer, as it seems to be the best so far.

Here are the declarations:
Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" (ByVal hConsoleOutput As Long, lpBuffer As Any, ByVal nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, lpReserved As Any) As Long

Declare Function WriteConsoleOutput Lib "kernel32" Alias "WriteConsoleOutputA" (ByVal hConsoleOutput As Long, lpBuffer As CHAR_INFO, dwBufferSize As COORD, dwBufferCoord As COORD, lpWriteRegion As SMALL_RECT) As Long

Declare Function WriteConsoleOutputAttribute Lib "kernel32" Alias "WriteConsoleOutputAttribute" (ByVal hConsoleOutput As Long, lpAttribute As Integer, ByVal nLength As Long, dwWriteCoord As COORD, lpNumberOfAttrsWritten As Long) As Long

Declare Function WriteConsoleOutputCharacter Lib "kernel32" Alias "WriteConsoleOutputCharacterA" (ByVal hConsoleOutput As Long, ByVal lpCharacter As String, ByVal nLength As Long, dwWriteCoord As COORD, lpNumberOfCharsWritten As Long) As Long

Here are the types:

        Char As Integer
        Attributes As Integer
End Type
        x As Integer
        y As Integer
End Type
        Left As Integer
        Top As Integer
        Right As Integer
        Bottom As Integer
End Type


Author Comment

ID: 1453090
Point have increased.  I had already performed the WRITECONSOLE function and it worked.  but considering I had to test this out on NT...The WRITECONSOLE created another DOS WINDOW.  I'm going to test this out the way it is intended...straight DOS application in a non-windows environment.  I'll see how that goes.

Provide an answer instead of a comment and point will be given...assuming this example works  :)   (But it's putting me in the right direction.)
LVL 13

Expert Comment

ID: 1453091
To whom are you talking. Maybe you can post the code you have so we can maybe use it as a starting point to help you some more.

Author Comment

ID: 1453092
Sorry, it was directed to either your (Mirkwood) or hddp666.  

(Refer to my last comment about it's current status.

Here is the code that I'm using:

Option Explicit

' Reference to a trasmittal object.
Private mthsendstream As transmittal
Declare Function AllocConsole Lib "kernel32" () As Long
Declare Function FreeConsole Lib "kernel32" () As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) _
        As Long
Declare Function GetStdHandle Lib "kernel32" (ByVal _
        nStdHandle As Long) As Long
Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" _
           (ByVal hConsoleOutput As Long, lpBuffer As Any, ByVal _
           nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, _
           lpReserved As Any) As Long
Public Const STD_OUTPUT_HANDLE = -11&

Private Sub Main()
Dim hConsole As Long
Dim command_line As String
Dim temp_date As String
Dim temp_time As String
Dim temp_db As String * 2
Dim temp_module As String * 20
Dim temp_partner As String * 10
Dim temp_doc As String * 10
Dim temp_doc_type As String * 12
Dim temp_comment As String * 80
Dim send_string As String
Dim X As Integer
Dim type_command As String
Dim Result As Long, sOut As String, cWritten As Long
command_line = Command()
If AllocConsole() Then
    hConsole = GetStdHandle(STD_OUTPUT_HANDLE)
End If
Set mthsendstream = New transmittal
    'Prepare EV log transaction
If command_line = "END" Then
    mthsendstream.data_stream = command_line
    temp_db = "EV"
    temp_date = Format(Date, "yyyy/mm/dd")
    temp_time = Format(Time, "hh:mm:ss")
    send_string = temp_db & command_line & temp_date & temp_time
    mthsendstream.data_stream = send_string
End If
    sOut = mthsendstream.data_stream & vbCrLf
    Result = WriteConsole(hConsole, ByVal sOut, Len(sOut), cWritten, _ ByVal 0&)
End Sub

>>Apologize for the confusion on the my previous response.

Author Comment

ID: 1453093
I've tried various alternatives with no success.  As a result, I have some residual fields defined that are left over from those.  Also, I haven't "cleaned" up the code yet either.
LVL 13

Accepted Solution

Mirkwood earned 300 total points
ID: 1453094
I've not found any method to connect to an existing window. What you can however do is use a small trick using copy and paste.
Copy the sentence to your clipboard. Find the console window (using findwindow). Get the handle to the system menu and call the paste function using sendmessage.
Maybe you can also use sendkeys or something.

Author Comment

ID: 1453095
The whole issue is a little more overhead than what it should be.  So, what I'll end up doing is setting a DOS error switch and let our batch processing product (XLNT) handle the check of the switch.  

However, I will give you the points.

Thanks for all the assistance.

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

688 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