View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Steve Yandl[_3_] Steve Yandl[_3_] is offline
external usenet poster
 
Posts: 117
Default Output a string to the console?

Toby,

Take a look at the line from the routine
strMsg = "echo " & strMsg & "&echo off"
Notice how I placed the & characters when I sent echo commands. The &
character when fed to cmd.exe works much like vbCrLf when you're writing VBA
or VBS. In the line above, the first and second & are used to concatenate
my string but the one inside the quotes and right before "echo off" causes
the "echo off" to be sent as a new line (which turns off the echo so you
don't have the command prompt waiting after your final line of text). Just
build up the variable strMsg so that you keep adding the lines of output but
be sure to add in an & between each line. Then at the end, use the line I
placed to append the text string with the echo and 'echo off'.

Steve Yandl


"Just Another Yahoo!" wrote in message
...
Wow, cool Steve!

That works well for a single line of output but I would need the ability
to output as the program moves along, just like a log file. As is, this
opens a new command window every time it's called. Maybe I could make it
into an object... I'll play some more with it. Thanks for the assistance
:-)
--
Toby Erkson
Excel 2003, WinXP

"Steve Yandl" wrote in message
...
Toby,

As I suggested in my earlier post, I suspect there is a more efficient
way to harvest output from the tasks your sheduler causes to execute.
However, if you do want text to a console window, here is an example. If
you launch this sub with some text as the argument, you get a command
interpreter console window (cmd.exe window) containing the text sent to
the sub. If the text argument is absent, you get the console window with
"Hello World"

'----------------------------------------------
Sub StringInConsole(Optional strMsg As String = "")

If Not Len(strMsg) 0 Then
strMsg = "Hello World"
End If

strMsg = "echo " & strMsg & "&echo off"

Shell "cmd.exe /k" & strMsg, vbNormalFocus

End Sub
'----------------------------------------------

That you could launch with a sub like
'---------------------------------------------
Sub MessageMe()
StringInConsole("This is a test of this fine VBA routine")
End Sub
'---------------------------------------------
or
'---------------------------------------------
Sub MessageMe()
StringInConsole
End Sub
'---------------------------------------------

Steve Yandl