Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Output a string to the console?

I'm looking for a simple way to output to the console (command line
window?). Can this be done in VBA?

The reason: I have a scheduler that can monitor the task it has executed
and capture any console output for later inspection. I want this as I would
like to send text to the console when an error occurs to help me figure
things out. I don't want a log file.

If you're familiar with VBScripting then what I'm looking for is something
like this -- wscript.echo "Hello world!".

TIA!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Output a string to the console?

HI

Maybe this is what you need.
You can output to the Immediate window, which you can see in the VBA editor.

Debug.Print "Hello world"

Regards,
Per

"Toby Erkson" skrev i meddelelsen
...
I'm looking for a simple way to output to the console (command line
window?). Can this be done in VBA?

The reason: I have a scheduler that can monitor the task it has executed
and capture any console output for later inspection. I want this as I
would like to send text to the console when an error occurs to help me
figure things out. I don't want a log file.

If you're familiar with VBScripting then what I'm looking for is something
like this -- wscript.echo "Hello world!".

TIA!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Output a string to the console?

Nope, since the workbook is executed automatically by the scheduler the
Immediate Window won't do me any good. The workbook is only seen by a human
when there's an error and the errors are generally due to the input file and
not the workbook.

"Per Jessen" wrote in message
...
HI

Maybe this is what you need.
You can output to the Immediate window, which you can see in the VBA
editor.

Debug.Print "Hello world"

Regards,
Per



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Output a string to the console?

Hmm, after re-reading this, just ignore that last sentence.
--
Toby Erkson
Excel 2003, WinXP

"Just Another Yahoo!" wrote in message
...
Nope, since the workbook is executed automatically by the scheduler the
Immediate Window won't do me any good. The workbook is only seen by a human
when there's an error and the errors are generally due to the input file and
not the workbook.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Output a string to the console?

Well, at least I'm consistent with asking the questions that can't be
answered, LOL
--
Toby Erkson
Excel 2003, WinXP

"Toby Erkson" wrote in message
...
I'm looking for a simple way to output to the console (command line
window?). Can this be done in VBA?

The reason: I have a scheduler that can monitor the task it has executed
and capture any console output for later inspection. I want this as I
would like to send text to the console when an error occurs to help me
figure things out. I don't want a log file.

If you're familiar with VBScripting then what I'm looking for is something
like this -- wscript.echo "Hello world!".

TIA!






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Output a string to the console?

Toby,

Have you looked at creating an instance of the "WScript.Shell" object and
using it's 'exec' method as an alternate means of capturing output from the
task and skip the console window?

If you do use a console type window, can you have the print output and also
have the normal prompt that appears when you launch cmd.exe or does that
prompt create problems for output retrieval?


Steve Yandl



"Toby Erkson" wrote in message
...
Well, at least I'm consistent with asking the questions that can't be
answered, LOL
--
Toby Erkson
Excel 2003, WinXP

"Toby Erkson" wrote in message
...
I'm looking for a simple way to output to the console (command line
window?). Can this be done in VBA?

The reason: I have a scheduler that can monitor the task it has executed
and capture any console output for later inspection. I want this as I
would like to send text to the console when an error occurs to help me
figure things out. I don't want a log file.

If you're familiar with VBScripting then what I'm looking for is
something like this -- wscript.echo "Hello world!".

TIA!





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Output a string to the console?

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




"Toby Erkson" wrote in message
...
Well, at least I'm consistent with asking the questions that can't be
answered, LOL
--
Toby Erkson
Excel 2003, WinXP

"Toby Erkson" wrote in message
...
I'm looking for a simple way to output to the console (command line
window?). Can this be done in VBA?

The reason: I have a scheduler that can monitor the task it has executed
and capture any console output for later inspection. I want this as I
would like to send text to the console when an error occurs to help me
figure things out. I don't want a log file.

If you're familiar with VBScripting then what I'm looking for is
something like this -- wscript.echo "Hello world!".

TIA!





  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Output a string to the console?

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



  #9   Report Post  
Posted to microsoft.public.excel.programming
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




  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Output a string to the console?

Well, I was hoping to not have to build a string. The goal is to simply
open the command window and spit out text as the program plods along instead
of waiting until it finishes (for better or for worse) to output a built-up
string because that would require error checking code, which is something
I'd like to avoid. Remember, the scheduler app. I use captures the command
window output as the executing program runs so if the executing program
fails for any reason -- be it gracefully or catastrophically -- the [saved]
command window text would show me the last point of noted execution.

Background: The person I replaced wrote many scripts and VBA code but w/o
good error trapping. Right now it's faster for me to put in these sort of
"echo" statements at key points in the VBA code than set up error
trapping -- that would be a long task with too small of a return. This
method would give me a better idea where the error occurred instead of just
"somewhere in this workbook" and it would allow me to insert break points in
appropriate locations. As I come across the rare error I add my error
checking/trapping as necessary.
--
Toby Erkson
Excel 2003, WinXP

"Steve Yandl" wrote in message
...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
UDF evaluate string output David Excel Programming 9 September 9th 08 08:02 AM
Console.Writeline output in VSTO Ed White Excel Programming 4 July 31st 08 06:42 PM
VBA String Output adds Quotes when I cut and paste to Notepad rfusee Excel Programming 1 September 18th 07 08:40 PM
Api to console application Jean-Yves[_2_] Excel Programming 4 August 17th 05 02:19 PM
string output needed David Excel Programming 2 January 31st 05 10:11 AM


All times are GMT +1. The time now is 02:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"