Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. Pretty complex approach compared to the simplicity of my suggestion! -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus |
#12
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Monday, November 12, 2018 at 6:10:15 PM UTC-5, GS wrote:
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. Pretty complex approach compared to the simplicity of my suggestion! -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus I can't argue with that. But I really liked the functionality of Tab(N) that allows you to specifically pick any column. Unlike vbTab that jumps to a discrete set of Tab positions. I was also unaware of regular expression processing in VBA until I saw a reference to VBScript.RegExp. As a Perl programmer who relies heavily on regular expressions I was delighted to find decent regexp support in VBA. Sometimes coding has to be fun !!. Thank you for contributing to the discussion. |
#13
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I can't argue with that. But I really liked the functionality of Tab(N) that
allows you to specifically pick any column. Unlike vbTab that jumps to a discrete set of Tab positions. I was also unaware of regular expression processing in VBA until I saw a reference to VBScript.RegExp. As a Perl programmer who relies heavily on regular expressions I was delighted to find decent regexp support in VBA. Sometimes coding has to be fun !!. Thank you for contributing to the discussion. I say "go with what you know" and so makes sense now why you chose this approach. And yes, coding IS fun!! -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Bypass error message to debug | Excel Programming | |||
Can't get length of a variant array passed to a subroutine | Excel Programming | |||
Error Message: NULL IDispatch passed to Autowrap() | Excel Discussion (Misc queries) | |||
VBA causing "Excel has encountered a problem" message | Excel Programming | |||
Problem encountered | Setting up and Configuration of Excel |