VB 6 to DOS Prompt

simonstre

What is this storage?
Joined
Mar 31, 2002
Messages
61
I'm developping a soft with VB 6 (I know, I know... it sucks, but it is a requirement) that will be launched from the command line. The only problem left is for the /h (help) argument... I've searched a lot and didn't find anything working in this context. Of course, I could create a new DOS Prompt window and ask the user to press a key to close it, but I find this a bit dirty. I'd like to print it in the same prompt window, if it is possible.
I searched on VB forums and I was answered by beguinners... you know, "You should put this into a form and place your text in a label" or some answers like that. I want the REAL solution :)

Any ideas?

*** I tried the print method... I didn't manage to make it work. ***
 

timwhit

Hairy Aussie
Joined
Jan 23, 2002
Messages
5,278
Location
Chicago, IL
So your help file is going to be some kind of text file that opens in the command prompt?

If you post some of your code I can probably help you.
 

simonstre

What is this storage?
Joined
Mar 31, 2002
Messages
61
Ok, here's an example of what I wanna do:

EDP_converter /h

This should give a short text (to have an example, type dir /h to the command line.) I could post my code, but it doesn't work :) So I don't see why I should do it. But, if you really need it, I'll post it.


Thanks!
 

timwhit

Hairy Aussie
Joined
Jan 23, 2002
Messages
5,278
Location
Chicago, IL
I've never written a program that runs on the command line in VB. But, is there a way to refer to the command line (cmd.exe) as an object. Because, then you could just do cmd.print textfile.txt or something like that. Other than that I am pretty stumped on this one.
 

Mercutio

Fatwah on Western Digital
Joined
Jan 17, 2002
Messages
22,228
Location
I am omnipresent
I've not done console apps with VB, but I know in Delphi (where I have), there's a syntax for working with console apps that way. IIRC, once the app was declared a console application, writing a line of output was as simple as doing a 'writeln "some text here"'

I'd be shocked if VB didn't have something similar, if you dug a bit in the references.
 

simonstre

What is this storage?
Joined
Mar 31, 2002
Messages
61
Timwhit : there's a way to refer a command line as an object, but only if I create a new instance of it. That's exactly what I don't want to do. :) But if there's no other way, I'll create a new one.

Mercutio : I know I can do it with Delphi... In fact, I've manage to made with Delphi in about 10 minutes, with some research on the net. But, with VB, after 9.5 hours of research, nothing came up... yes, I can use some API calls to handle a new console instance. But what about the existing one? I've found absolutely nothing on this. Perhaps that I don't search correctly (I'm just a frenchie after all :roll: )


Any other idea?
 

Cliptin

Wannabe Storage Freak
Joined
Jan 22, 2002
Messages
1,206
Location
St. Elmo, TN
Website
www.whstrain.us
simonstre said:
Timwhit : there's a way to refer a command line as an object, but only if I create a new instance of it. That's exactly what I don't want to do. :) But if there's no other way, I'll create a new one.

Mercutio : I know I can do it with Delphi... In fact, I've manage to made with Delphi in about 10 minutes, with some research on the net. But, with VB, after 9.5 hours of research, nothing came up... yes, I can use some API calls to handle a new console instance. But what about the existing one? I've found absolutely nothing on this. Perhaps that I don't search correctly (I'm just a frenchie after all :roll: )


Any other idea?

Maybe your teacher is trying to show you the inadequacies of VB!

Whenever I had spend an inordinate amount of time (9.5 hours?) researching a function/problem my teachers would scold me for not having come to them sooner. In the real world you would be able to go to the senior programmer or the developer of the software for help.
 

time

Storage? I am Storage!
Joined
Jan 18, 2002
Messages
4,932
Location
Brisbane, Oz
10 minutes in Delphi, 9.5 hours in VB and it still doesn't work. I don't see the problem. Isn't that perfectly normal? :wink:
 

time

Storage? I am Storage!
Joined
Jan 18, 2002
Messages
4,932
Location
Brisbane, Oz
Seriously, a quick search on google came up with this.

I grant you that MsgBox doesn't sound like the appropriate function, but presumably it works differently with this compilation profile?
 

simonstre

What is this storage?
Joined
Mar 31, 2002
Messages
61
Cliptin: duh. I'm the senior programmer in VB, here. And my teachers won't help me, because they only know C++/Java. They believe (and I guess it's true) that all MS products aren't appropriate to build a software solution. :)

Time: this is useful to accept command line arguments, not to return something to it. I guess I'll just create a new instance of it... :( Man, I really hate to do dumbs things just because it's not possible to do it correctly.


Thanks a lot guys... and please don't stop to search. But I doubt there's anything that can be done in this case.
 

simonstre

What is this storage?
Joined
Mar 31, 2002
Messages
61
Time : and msgbox works EXACTLY the same in this compilation profile... You didn't expected seriously that VB would be smart enough to evaluate the context, no?
 

simonstre

What is this storage?
Joined
Mar 31, 2002
Messages
61
I want to share this painful moment with you all : I'm able, with a simple batch file, to do what I want. echo [myString] works fine... But, when I want to do this with VB, with Shell, ShellExecute, CreateProcess, etc... etc... the only thing I get is file not found.

Ugrade to VB, they said. It'll make your work easier...
 

Will Rickards WT

Learning Storage Performance
Joined
Jun 19, 2002
Messages
433
Location
Pennsylvania, USA
Website
www.willrickards.net
I thought using GetStdHandle and WriteConsole would work... but GetStdHandle doesn't seem to work.

The code I tried:
Option Explicit

Public Const STD_OUTPUT_HANDLE As Long = -11
Public Const INVALID_HANDLE_VALUE As Long = -1

Public Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long
Public 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

Sub Main()

Dim lngHandle As Long
Dim lngBufferLength As Long
Dim strBuffer As String
Dim lngWritenLength As Long
Dim lngError As Long

strBuffer = "Hello World"
lngBufferLength = Len(strBuffer) + 1

lngHandle = GetStdHandle(STD_OUTPUT_HANDLE)

If lngHandle <> INVALID_HANDLE_VALUE Then

If WriteConsole(lngHandle, strBuffer, lngBufferLength, lngWritenLength, 0) Then

MsgBox "Hello World Worked"

Else

MsgBox "Hello World Failed"

End If

Else

MsgBox "Invalid Handle Returned " & Hex(lngHandle)

End If

End Sub
 

Mercutio

Fatwah on Western Digital
Joined
Jan 17, 2002
Messages
22,228
Location
I am omnipresent
Well, if you want to be a smartass, I think I still have all the floppies to Visual Basic for DOS somewhere...
 

simonstre

What is this storage?
Joined
Mar 31, 2002
Messages
61
Will Rickards WT said:
I thought using GetStdHandle and WriteConsole would work... but GetStdHandle doesn't seem to work.

Exactly what I tried. Failed miserably. :)
 

simonstre

What is this storage?
Joined
Mar 31, 2002
Messages
61
Cliptin said:
simonstre said:
Cliptin: duh. I'm the senior programmer in VB.

Ahh. I guess I can't "console" you then.

Very funny :)


Thank you, Will, it works well. I was a few code lines short of a solution! But now its ok.
 
Top