Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Old November 6th 18, 10:43 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Nov 2014
Posts: 22
Default Problem encountered with Debug.Print message being passed to subroutine

I have developed a DebugSupport class that gives the option of directing Debug.Print output to Immediate Window or Immediate Window and disk file or disk file only. This class has a method output_line. So, in my code I replace
Debug.Print "Line: " & "Test stuff"
with
Public dp as New DebugSupport
dp.output_line ("Line: " & "Test stuff")

This works fine. However if the Debug.Print message contains formatting functions such as Tab() or Spc(), then I get a compile error i.e.
dp.output_line ("Line: "; Tab(10); "Test stuff") Compile error

So, my question is how do I pass such a message into a subroutine.

The method output_line does two things. It puts the input argument into a Debug.Print statement and then prints it to disk. I assume that the Tab() function is specific to Debug.Print and that I would have to supply some code to replicate this formatting control while printing to disk. That is not difficult. But I am stumped by the compile error.
Thanks

  #2   Report Post  
Old November 7th 18, 01:59 AM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Apr 2015
Posts: 977
Default Problem encountered with Debug.Print message being passed to subroutine

I have developed a DebugSupport class that gives the option of directing
Debug.Print output to Immediate Window or Immediate Window and disk file or
disk file only. This class has a method output_line. So, in my code I
replace Debug.Print "Line: " & "Test stuff" with
Public dp as New DebugSupport dp.output_line ("Line: "
& "Test stuff")

This works fine. However if the Debug.Print message contains formatting
functions such as Tab() or Spc(), then I get a compile error i.e.
dp.output_line ("Line: "; Tab(10); "Test stuff") Compile error

So, my question is how do I pass such a message into a subroutine.

The method output_line does two things. It puts the input argument into a
Debug.Print statement and then prints it to disk. I assume that the Tab()
function is specific to Debug.Print and that I would have to supply some code
to replicate this formatting control while printing to disk. That is not
difficult. But I am stumped by the compile error. Thanks


Try constructing the entire string BEFORE passing to your routine so it's
already the output string formatted as desired, ..perhaps!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
  #3   Report Post  
Old November 7th 18, 07:53 AM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Nov 2014
Posts: 22
Default Problem encountered with Debug.Print message being passed to subroutine

On Tuesday, November 6, 2018 at 7:59:45 PM UTC-5, GS wrote:
I have developed a DebugSupport class that gives the option of directing
Debug.Print output to Immediate Window or Immediate Window and disk file or
disk file only. This class has a method output_line. So, in my code I
replace Debug.Print "Line: " & "Test stuff" with
Public dp as New DebugSupport dp.output_line ("Line: "
& "Test stuff")

This works fine. However if the Debug.Print message contains formatting
functions such as Tab() or Spc(), then I get a compile error i.e.
dp.output_line ("Line: "; Tab(10); "Test stuff") Compile error

So, my question is how do I pass such a message into a subroutine.

The method output_line does two things. It puts the input argument into a
Debug.Print statement and then prints it to disk. I assume that the Tab()
function is specific to Debug.Print and that I would have to supply some code
to replicate this formatting control while printing to disk. That is not
difficult. But I am stumped by the compile error. Thanks


Try constructing the entire string BEFORE passing to your routine so it's
already the output string formatted as desired, ..perhaps!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


Actually, I have a more fundamental difficulty
Debug.Print "A"; Tab(60); "B" ' works properly
but
Dim stringa as string
stringa = "A; Tab(60); B"
Debug.Print stringa ' gives output: A; Tab(60); B

Is there a way to fix this ?

  #4   Report Post  
Old November 7th 18, 06:57 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Apr 2015
Posts: 977
Default Problem encountered with Debug.Print message being passed to subroutine

On Tuesday, November 6, 2018 at 7:59:45 PM UTC-5, GS wrote:
I have developed a DebugSupport class that gives the option of directing
Debug.Print output to Immediate Window or Immediate Window and disk file or
disk file only. This class has a method output_line. So, in my code I
replace Debug.Print "Line: " & "Test stuff" with
Public dp as New DebugSupport dp.output_line
("Line: " & "Test stuff")

This works fine. However if the Debug.Print message contains formatting
functions such as Tab() or Spc(), then I get a compile error i.e.
dp.output_line ("Line: "; Tab(10); "Test stuff") Compile error

So, my question is how do I pass such a message into a subroutine.

The method output_line does two things. It puts the input argument into a
Debug.Print statement and then prints it to disk. I assume that the Tab()
function is specific to Debug.Print and that I would have to supply some
code to replicate this formatting control while printing to disk. That is
not difficult. But I am stumped by the compile error. Thanks


Try constructing the entire string BEFORE passing to your routine so it's
already the output string formatted as desired, ..perhaps!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


Actually, I have a more fundamental difficulty
Debug.Print "A"; Tab(60); "B" ' works properly
but
Dim stringa as string
stringa = "A; Tab(60); B"
Debug.Print stringa ' gives output: A; Tab(60); B

Is there a way to fix this ?


sA = "A;" & Tab(60) & "; B"
Debug.Print sA

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
  #5   Report Post  
Old November 7th 18, 06:59 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Apr 2015
Posts: 977
Default Problem encountered with Debug.Print message being passed to subroutine

On Tuesday, November 6, 2018 at 7:59:45 PM UTC-5, GS wrote:
I have developed a DebugSupport class that gives the option of directing
Debug.Print output to Immediate Window or Immediate Window and disk file
or disk file only. This class has a method output_line. So, in my code
I replace Debug.Print "Line: " & "Test stuff" with
Public dp as New DebugSupport dp.output_line
("Line: " & "Test stuff")

This works fine. However if the Debug.Print message contains formatting
functions such as Tab() or Spc(), then I get a compile error i.e.
dp.output_line ("Line: "; Tab(10); "Test stuff") Compile error

So, my question is how do I pass such a message into a subroutine.

The method output_line does two things. It puts the input argument into a
Debug.Print statement and then prints it to disk. I assume that the
Tab() function is specific to Debug.Print and that I would have to supply
some code to replicate this formatting control while printing to disk.
That is not difficult. But I am stumped by the compile error. Thanks

Try constructing the entire string BEFORE passing to your routine so it's
already the output string formatted as desired, ..perhaps!

-- Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


Actually, I have a more fundamental difficulty
Debug.Print "A"; Tab(60); "B" ' works properly
but
Dim stringa as string
stringa = "A; Tab(60); B"
Debug.Print stringa ' gives output: A; Tab(60); B

Is there a way to fix this ?


sA = "A;" & Tab(60) & "; B"
Debug.Print sA


Minus the semicolons...

Dim sA$
sA = "A" & Tab(60) & "B"
Debug.Print sA

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #6   Report Post  
Old November 7th 18, 07:40 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Nov 2014
Posts: 22
Default Problem encountered with Debug.Print message being passed to subroutine

On Wednesday, November 7, 2018 at 12:59:49 PM UTC-5, GS wrote:
On Tuesday, November 6, 2018 at 7:59:45 PM UTC-5, GS wrote:
I have developed a DebugSupport class that gives the option of directing
Debug.Print output to Immediate Window or Immediate Window and disk file
or disk file only. This class has a method output_line. So, in my code
I replace Debug.Print "Line: " & "Test stuff" with
Public dp as New DebugSupport dp.output_line
("Line: " & "Test stuff")

This works fine. However if the Debug.Print message contains formatting
functions such as Tab() or Spc(), then I get a compile error i.e.
dp.output_line ("Line: "; Tab(10); "Test stuff") Compile error

So, my question is how do I pass such a message into a subroutine.

The method output_line does two things. It puts the input argument into a
Debug.Print statement and then prints it to disk. I assume that the
Tab() function is specific to Debug.Print and that I would have to supply
some code to replicate this formatting control while printing to disk.
That is not difficult. But I am stumped by the compile error. Thanks

Try constructing the entire string BEFORE passing to your routine so it's
already the output string formatted as desired, ..perhaps!

-- Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion

Actually, I have a more fundamental difficulty
Debug.Print "A"; Tab(60); "B" ' works properly
but
Dim stringa as string
stringa = "A; Tab(60); B"
Debug.Print stringa ' gives output: A; Tab(60); B

Is there a way to fix this ?


sA = "A;" & Tab(60) & "; B"
Debug.Print sA


Minus the semicolons...

Dim sA$
sA = "A" & Tab(60) & "B"
Debug.Print sA

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


I tried your suggestion but still getting a syntax error (Excel 2010) with or without the semicolons.
  #7   Report Post  
Old November 7th 18, 10:14 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Apr 2015
Posts: 977
Default Problem encountered with Debug.Print message being passed to subroutine

On Wednesday, November 7, 2018 at 12:59:49 PM UTC-5, GS wrote:
On Tuesday, November 6, 2018 at 7:59:45 PM UTC-5, GS wrote:
I have developed a DebugSupport class that gives the option of directing
Debug.Print output to Immediate Window or Immediate Window and disk file
or disk file only. This class has a method output_line. So, in my code
I replace Debug.Print "Line: " & "Test stuff" with
Public dp as New DebugSupport
dp.output_line ("Line: " & "Test stuff")

This works fine. However if the Debug.Print message contains formatting
functions such as Tab() or Spc(), then I get a compile error i.e.
dp.output_line ("Line: "; Tab(10); "Test stuff") Compile
error

So, my question is how do I pass such a message into a subroutine.

The method output_line does two things. It puts the input argument into
a Debug.Print statement and then prints it to disk. I assume that the
Tab() function is specific to Debug.Print and that I would have to
supply some code to replicate this formatting control while printing
to disk. That is not difficult. But I am stumped by the compile error.
Thanks

Try constructing the entire string BEFORE passing to your routine so it's
already the output string formatted as desired, ..perhaps!

-- Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion

Actually, I have a more fundamental difficulty
Debug.Print "A"; Tab(60); "B" ' works properly
but
Dim stringa as string
stringa = "A; Tab(60); B"
Debug.Print stringa ' gives output: A; Tab(60); B

Is there a way to fix this ?

sA = "A;" & Tab(60) & "; B"
Debug.Print sA


Minus the semicolons...

Dim sA$
sA = "A" & Tab(60) & "B"
Debug.Print sA

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


I tried your suggestion but still getting a syntax error (Excel 2010) with or
without the semicolons.


Oops, ..my bad! Try...

Dim s1$
s1 = "A" & vbTab & "B"
Debug.Print s1

-OR-
to set spacing...

Dim s1$
s1 = "A" & Space(60) & "B"
Debug.Print s1

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
  #8   Report Post  
Old November 7th 18, 10:54 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Apr 2015
Posts: 977
Default Problem encountered with Debug.Print message being passed to subroutine

Note that using vbTab applies the tab spacing set on the VBE OptionsGeneral
tab, whereas using the Space() function allows you to specify the spacing
between string sets.

I have the following function that accepts an Integer arg for the spacing I
want to use between sections when building strings. I also know that "Tab" is a
keyword and so have no idea why I didn't pick up on that; - sory, my bad!

So...

Public Function SetTab$(iLen%)
' Returns a set length string of spaces
' Args: iLen% The number of spaces

SetTab = Space(iLen)
End Function 'SetTab()

...and I use it like so...

Sub test_SetTab()
Dim s1$
s1 = "A" & vbTab & "B" & vbTab & "C"
Debug.Print s1
s1 = "Part1:" & SetTab(10) & "Part2;" & SetTab(5) & "Part3!"
Debug.Print s1
End Sub

...which returns the following:

A B C
Part1: Part2; Part3!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
  #9   Report Post  
Old November 12th 18, 05:23 AM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Nov 2014
Posts: 22
Default Problem encountered with Debug.Print message being passed to subroutine

On Wednesday, November 7, 2018 at 4:54:30 PM UTC-5, GS wrote:
Note that using vbTab applies the tab spacing set on the VBE OptionsGeneral
tab, whereas using the Space() function allows you to specify the spacing
between string sets.

I have the following function that accepts an Integer arg for the spacing I
want to use between sections when building strings. I also know that "Tab" is a
keyword and so have no idea why I didn't pick up on that; - sory, my bad!

So...

Public Function SetTab$(iLen%)
' Returns a set length string of spaces
' Args: iLen% The number of spaces

SetTab = Space(iLen)
End Function 'SetTab()

..and I use it like so...

Sub test_SetTab()
Dim s1$
s1 = "A" & vbTab & "B" & vbTab & "C"
Debug.Print s1
s1 = "Part1:" & SetTab(10) & "Part2;" & SetTab(5) & "Part3!"
Debug.Print s1
End Sub

..which returns the following:

A B C
Part1: Part2; Part3!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


Thank you for your posting. However, I have found the Tab() and Spc() functions very useful in formatting Debug.Print output. I have now concluded that it is not possible to put a Debug.Print message containing those function calls into a string and have that string output by Debug.Print and expect the formatting to be implemented.

I have developed a strategy to overcome this limitation. Please check my next posting for details.
  #10   Report Post  
Old November 12th 18, 06:09 AM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Nov 2014
Posts: 22
Default Problem encountered with Debug.Print message being passed to subroutine

On Tuesday, November 6, 2018 at 4:43:23 PM UTC-5, Desmond Walsh wrote:
I have developed a DebugSupport class that gives the option of directing Debug.Print output to Immediate Window or Immediate Window and disk file or disk file only. This class has a method output_line. So, in my code I replace
Debug.Print "Line: " & "Test stuff"
with
Public dp as New DebugSupport
dp.output_line ("Line: " & "Test stuff")

This works fine. However if the Debug.Print message contains formatting functions such as Tab() or Spc(), then I get a compile error i.e.
dp.output_line ("Line: "; Tab(10); "Test stuff") Compile error

So, my question is how do I pass such a message into a subroutine.

The method output_line does two things. It puts the input argument into a Debug.Print statement and then prints it to disk. I assume that the Tab() function is specific to Debug.Print and that I would have to supply some code to replicate this formatting control while printing to disk. That is not difficult. But I am stumped by the compile error.
Thanks


In my opinion, the problem is due to a limitation on how Debug.Print handles a message enclosed in a string. It is unable to recognize usage of the formatting functions Tab() and Spc(). I have developed the following workaround to overcome this restriction ;

1 Add a new method ReplaceDebugStatements to the class DebugSupport. It
modifies Debug.Print statements as follows ;
;Tab(N) - & "Tab(N)";
;Spc(N) - & "Spc(N)";
Debug.Print message - dp.output_line (message)
NOTE 1: The code is modelled on Chip Pearson's SearchCodeModule
(www.cpearson.com/Excel). The edits are done with regular expressions
using VBScript.RegExp
NOTE 2: The code handles the following complexities ;
The token: Debug.Print appears in a comment
A Debug.Print statement is commented out
A Debug.Print statement is split over several lines with the last
line containing an optional comment
NOTE 3: This code is an example of an Excel workbook modifying its own VBA
code. The target of ReplaceDebugStatements is the VBA source code in a
different module of the workbook

2 Add code to the method output_line that replaces occurrences of Tab() and
Spc() by correct spacing format. The implementation uses
VBScript.RegExp,and the functions Replace,Split and Space

For maintenance ease, the ClassModule DebugSupport resides in a dedicated workbook debugsupport.xlsm. The process of incorporating this code in a new workbook is automated by the subroutine ArrangeDebugSupport in PERSONAL.XLSM. ArrangeDebugSupport creates the appropiate modules and copies in the source code from debugsupport.xlsm.

With these changes, any VBA source module may be switched from debug processing handled by Debug.Print to debug processing handled by ClassModule DebugSupport. The important gain is the ability to capture the output flow in the Immediate Window in a disk file.


The functions Tab() and Spc() are very useful in helping to format Debug.Print output with columns of data that need to be lined up. A simple strategy is to work with Debug.Print until the output is formatted optimally. Then switch to DebugSupport debug processing.


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
Bypass error message to debug Teddy Excel Programming 5 March 8th 10 01:43 AM
Can't get length of a variant array passed to a subroutine Craig Remillard Excel Programming 6 November 23rd 09 09:27 PM
Error Message: NULL IDispatch passed to Autowrap() Aviral Sharma Excel Discussion (Misc queries) 0 March 13th 09 06:13 AM
VBA causing "Excel has encountered a problem" message arch Excel Programming 5 May 23rd 07 07:18 PM
Problem encountered Pat Setting up and Configuration of Excel 1 March 3rd 06 04:01 PM


All times are GMT +1. The time now is 07:37 AM.

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

About Us

"It's about Microsoft Excel"

 

Copyright © 2017