View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
GS[_6_] GS[_6_] is offline
external usenet poster
 
Posts: 1,182
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