| | |
Writing to Console
Thread Solved |
Hi All,
I have a VB6 application which can work in UI as well as in CMD mode. Now when I am running it in CMD mode I need to write few line into the console after completion of the program before quitting the application. The rest of the application is working perfectly fine but I am not able to write something into the console
I tried the following but it does not work
Kindly help. I need to write the output in the same console window from where the application is invoked, not in a new window that the application would open.
I have a VB6 application which can work in UI as well as in CMD mode. Now when I am running it in CMD mode I need to write few line into the console after completion of the program before quitting the application. The rest of the application is working perfectly fine but I am not able to write something into the console
I tried the following but it does not work
VB Syntax (Toggle Plain Text)
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 Declare Function SetConsoleCtrlHandler Lib "kernel32" (ByVal HandlerRoutine As Long, ByVal Add As Long) As Long Public Const STD_OUTPUT_HANDLE = -11& Public hndl As Long Sub Main() Dim strWord As String Dim cWritten As Long Dim successStat As Boolean On Error GoTo Hndlr strWord = "Hello!" & vbCrLf hndl = GetStdHandle(STD_OUTPUT_HANDLE) successStat = WriteConsole(hndl, ByVal strWord, Len(strWord), cWritten, ByVal 0&) Hndlr: Debug.Print Err.Description Debug.Print Err.Number Resume Next End Sub
Kindly help. I need to write the output in the same console window from where the application is invoked, not in a new window that the application would open.
Regards
Shouvik
Shouvik
Hi All,
I could do the required by doing the following
But then whenever we open the VB Application in UI mode it shows a CMD window at the background along with the Form. So to hide it I had to do the following as well
in the Sub Main()
Now it works fine both for Console mode as well as UI mode.
I could do the required by doing the following
"<drive>:\Program Files\Microsoft Visual Studio\vb98\LINK.EXE" /EDIT /SUBSYSTEM:CONSOLE <my_app_name.exe>" .But then whenever we open the VB Application in UI mode it shows a CMD window at the background along with the Form. So to hide it I had to do the following as well
VB Syntax (Toggle Plain Text)
ConsoleHandle = FindWindow("ConsoleWindowClass", App.Path & "\<my_app_name.exe>") ShowWindow ConsoleHandle, SW_HIDE
in the Sub Main()
Now it works fine both for Console mode as well as UI mode.
Last edited by shouvik.d; Dec 24th, 2008 at 9:21 am.
Regards
Shouvik
Shouvik
![]() |
Similar Threads
- How to output this VB code in Console? (VB.NET)
- Clear the console and/or use system calls (Java)
- How can I change console application font size? (C)
- substitute for conio.h in linux (C)
- Some Simple Console App Questons (Java) (Java)
- HELP! Illegal Character Constant in a Console Application (C++)
- writing a simple cat program (C)
- hey guys; having some trouble with this program i'm writing (Java)
- How do I read a line? (Java)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Adding Time in VB 6.0
- Next Thread: Reg.DATABASE and Refresh
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





