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


VB Console Application

Posted on 1999-07-11
Medium Priority
Last Modified: 2010-05-02
I am trying to write a VB application that can send output back to the Console that called it. i.e. I am trying to write a command line style program. I have tried using the ApiCall WriteFile but the output seems to go down a hole. Any ideas ?
Question by:stewa
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
LVL 13

Expert Comment

ID: 1523520
The easiest way is just to communicate with stdout and stdin.
Here is a sample of a VB application that does this 


Author Comment

ID: 1523521
Sorry the Link doesn't work.
I can get stdout to work using ">" but I cannot get it to display on the console
LVL 13

Expert Comment

ID: 1523522
Industry Leaders: 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!


Author Comment

ID: 1523523
I am already using cgi4vb, have you managed to get it to output directly to the Console ?
LVL 13

Accepted Solution

Mirkwood earned 600 total points
ID: 1523525
Option Explicit

   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&

Sub Main()

Dim hConsole As Long

Dim a

   Dim Result As Long, sOut As String, cWritten As Long
  a = AllocConsole()
       hConsole = GetStdHandle(STD_OUTPUT_HANDLE)
     sOut = "Hi There dsfkj kdsfkjldfs kjdfslj kldsf jk" & vbCrLf
     Result = WriteConsole(hConsole, ByVal sOut, Len(sOut), cWritten, _
                           ByVal 0&)
End Sub  

LVL 13

Expert Comment

ID: 1523526
You won't see the output I think in the console.
Update problem

Author Comment

ID: 1523527
Thanks for your response.

I the end I obtained some software/code from which alters the EXE header from Gui to Console App.

If you could make use of this code then I can e-mail it to you.

LVL 13

Expert Comment

ID: 1523528
Sure email it. See my profile.


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

661 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