[Implemented] send the DebugOutput to the ClipBoard
[Implemented] send the DebugOutput to the ClipBoard
We already have the ability to programmatically
(1) Clear the DebugOutput
(2) Save the DebugOutput
All that's missing is #3 : the ability to send the DebugOutput to the system's clipboard.
Can we hope to have this sometimes ???
That would be immensely useful.
As well, the Help File should mention the above related functions in the general Debugging page and should link to their Help File page.
Thank you.
(1) Clear the DebugOutput
(2) Save the DebugOutput
All that's missing is #3 : the ability to send the DebugOutput to the system's clipboard.
Can we hope to have this sometimes ???
That would be immensely useful.
As well, the Help File should mention the above related functions in the general Debugging page and should link to their Help File page.
Thank you.
PB Forums : Proof positive that 2 heads (or more...) are better than one 

Re: Programmatically send the DebugOutput to the ClipBoard
Use SetClipboardText().
- Fangbeast
- PureBasic Protozoa
- Posts: 4789
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Re: Programmatically send the DebugOutput to the ClipBoard
Blue wants the clipboard to work with debug data. SetClipboardText() does not work with debug data.Dude wrote:Use SetClipboardText().
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Re: Programmatically send the DebugOutput to the ClipBoard
What I mean is, since he already knows what the debug output holds (since he put it there), why not just have an ongoing string of such output (such as DebugOutput$) and then just SetClipboardText(DebugOutput$) when the need arises?
Re: Programmatically send the DebugOutput to the ClipBoard
There's always a way to do something differently. But that's besides the point here.Dude wrote:[...] since he already knows what the debug output holds (since he put it there), why not just have an ongoing string of such output [...]
What you describe as a workaround is, of course, exactly what you, me and everybody else is already doing and has been doing forever. Nothing original in that solution.

But, again, that's not the point here, is it ?
The object of this section is to suggest, and possibly explain, ideas for additional conveniences that future releases of the IDE could benefit from.
Think of the built-in functions that PB provides to programmatically clear and save the Debug Output window. Strictly speaking, who needs them ? There already exist buttons at the top of the Debug Output window that do exactly that ! All you have to do is press them.

By your reasoning, what is being asked here is totally ridiculous : there's already a button at the top of the Debug Output window that sends everything to the Clipboard !

Maybe you should read and read again the title of the section and meditate on it.

Last edited by Blue on Tue Mar 31, 2015 3:55 pm, edited 1 time in total.
PB Forums : Proof positive that 2 heads (or more...) are better than one 

Re: Programmatically send the DebugOutput to the ClipBoard
Strictly speaking: clearing or saving the debug window at runtime is a different concept, because the programmer may need to clear or save it before each start of a recurring loop that they cannot determine the start of (thinking speed reasons mainly). You can't manually do that by clicking the mouse, so that argument is totally moot.Blue wrote:Think of the built-in functions that PB provide to clear and the Debug Output window. Strictly speaking, who needs them ?

On the other hand, since I as the coder was the one who put the text in the debug output, I can already programmatically copy it to the clipboard at any time anyway, so I don't see how much more convenient a command could make it. <Shrugs>.

This is what I mean:
Code: Select all
For a=1 To 100
n$+Str(Random(1000))+#CRLF$
Debug n$ ; Send information to Debug Output.
Next
SetClipboardText(n$) ; Copy contents of Debug Output.

Last edited by Dude on Tue Mar 31, 2015 3:53 pm, edited 1 time in total.
Re: Programmatically send the DebugOutput to the ClipBoard
Seriously Dude, why do you insist on showing others how to do the obvious ?Dude wrote:[...]
This is what I mean:
Code: Select all
For a=1 To 100 n$+Str(Random(1000))+#CRLF$ Debug n$ ; Send information to Debug Output. Next SetClipboardText(n$) ; Copy contents of Debug Output.

Do you really think that your point was not clear to anyone the very first time ?

Besides, supposing one codes your suggested workaround, can you not see that the requested 'convenience' could replace hundreds of 'add this to the outputSting$' lines in the code with a single request, just before the final 'End' : 'Now send everything to the clipboard' so i can just switch to my text editor, or Excel, or whatever, and start working with the pasted data... I'm exaggerating, of course, since all i have to do currently is bring the DebugOutput window to the front, click the 'Copy' button, and achieve the same outcome. Couldn't be simpler, really.


Last edited by Blue on Thu Apr 02, 2015 6:46 pm, edited 3 times in total.
PB Forums : Proof positive that 2 heads (or more...) are better than one 

Re: Programmatically send the DebugOutput to the ClipBoard
Edited my post above yours. Thanks for the discussion. 

- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Programmatically send the DebugOutput to the ClipBoard
Just for fun in the meantime:
run the code and paste into your ide... should work.
Code: Select all
Procedure EnumC(hwnd, lParam)
cn$ = Space(255)
GetClassName_(hwnd, @cn$, 255)
If FindString(cn$, "RichEdit")
PokeI(lParam, hwnd)
ProcedureReturn 0
Else
ProcedureReturn 1
EndIf
EndProcedure
Procedure Enum(hwnd, lParam)
wn$ = Space(255)
edit.i
GetWindowText_(hwnd, @wn$, 255)
If FindString(wn$, "Debug Output -")
EnumChildWindows_(hwnd, @EnumC(), @edit)
PokeI(lParam, edit)
ProcedureReturn 0
Else
ProcedureReturn 1
EndIf
EndProcedure
Procedure.s GetDebugText()
Static lastsize=0
Protected edit.i, result$
EnumWindows_(@Enum(), @edit)
size = SendMessage_(edit, #WM_GETTEXTLENGTH, 0, 0)
start=ElapsedMilliseconds()
While size=lastsize
size = SendMessage_(edit, #WM_GETTEXTLENGTH, 0, 0)
If ElapsedMilliseconds()-start>200
Break
EndIf
Wend
If size
lastsize=size
size+SizeOf(Character)
result$ = Space(size)
SendMessage_(edit, #WM_GETTEXT, size, @result$)
ProcedureReturn result$
Else
ProcedureReturn ""
EndIf
EndProcedure
Debug "1234567890"
Debug "Hello"
Debug 99
Debug 17*3
SetClipboardText(GetDebugText())
Last edited by netmaestro on Thu Apr 02, 2015 6:03 pm, edited 1 time in total.
BERESHEIT
Re: Programmatically send the DebugOutput to the ClipBoard
netmaestro's code made cross-platform:
Code: Select all
Procedure CopyDebugOutput()
ShowDebugOutput()
Delay(500)
Protected tempFile.s = GetTemporaryDirectory()+"TMP_PB_DEBUG_"+Hex(Random($FFFFFF))+".txt"
SaveDebugOutput(tempFile)
Delay(500)
Protected file = ReadFile(#PB_Any, tempFile, #PB_File_SharedRead|#PB_File_NoBuffering)
If file
Protected stringFormat = ReadStringFormat(file)
;ClearClipboard()
SetClipboardText( ReadString(file,stringFormat|#PB_File_IgnoreEOL) )
CloseFile(file)
EndIf
DeleteFile(tempFile,#PB_FileSystem_Force)
EndProcedure
Debug "Some text"
Debug "Some more text"
CopyDebugOutput()
MessageRequester("INFO", GetClipboardText())
Re: Programmatically send the DebugOutput to the ClipBoard
hm. Netmaestros code not work on Win8.1 x64
And Danilos code only works with PB5.31 x86.... why ?
With other PB versions, the output is empty (5.24 x86/x64 and 5.31x64) .....
I tested with Unicode and ASCII mode....
And Danilos code only works with PB5.31 x86.... why ?
With other PB versions, the output is empty (5.24 x86/x64 and 5.31x64) .....
I tested with Unicode and ASCII mode....
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Programmatically send the DebugOutput to the ClipBoard
Change all my .i to .l and PokeI to PokeL and it should work on x64.
BERESHEIT
Re: Programmatically send the DebugOutput to the ClipBoard
Wrote it with PB 5.31 x64 and works here. But I also noticed some strange things,
that's why I had to insert the delays and ShowDebugOutput().
Without the delays and ShowDebugOutput() I get no file or empty files most of the time:
Looks like SaveDebugOutput() does not flush and close the file correctly, because
the file can only be used after a delay.
After the delay, the file is still empty and does not contain "abc". I need to use ShowDebugOutput():
Here is the example from the PB Help (I just used d:\ instead c:\):
Gives me an empty file. PB 5.31 x64 on Windows 8.1
It works here when I put ShowDebugOutput() in front of the loop (before the first 'Debug' statement).
Looks like some new bugs.
that's why I had to insert the delays and ShowDebugOutput().
Without the delays and ShowDebugOutput() I get no file or empty files most of the time:
Code: Select all
Debug "abc"
tempFile.s = GetTemporaryDirectory()+"TMP_PB_DEBUG_"+Hex(Random($FFFFFF))+".txt"
SaveDebugOutput(tempFile)
Debug FileSize(tempFile) ; -1, file does not exist
Delay(500)
Debug FileSize(tempFile) ; 0, empty file
the file can only be used after a delay.
After the delay, the file is still empty and does not contain "abc". I need to use ShowDebugOutput():
Code: Select all
Debug "abc"
ShowDebugOutput() : Delay(500)
tempFile.s = GetTemporaryDirectory()+"TMP_PB_DEBUG_"+Hex(Random($FFFFFF))+".txt"
SaveDebugOutput(tempFile)
Debug FileSize(tempFile) ; -1, file does not exist
Delay(500)
Debug FileSize(tempFile) ; 5
Code: Select all
For i = 1 To 100
Debug Random(i)
Next i
SaveDebugOutput("d:\log.txt")
It works here when I put ShowDebugOutput() in front of the loop (before the first 'Debug' statement).
Looks like some new bugs.

Re: Programmatically send the DebugOutput to the ClipBoard
@NetMaestro :
Seems to work perfectly (PB 5.31 x86 under Win 8.1 x64) so far. Thank you !
How did you just pull such a neat bit of magic out of your hat all of a sudden?
That's gotta be a mighty big hat you have there, or is it the head under the hat that is so big ?
I'll explore that mystery later, but for now, suffice it to say that your solution does wonders for my nerves.
When you're dealing with over 1000 lengthy lines of data per output, your solution is a major help and time saver.
@Danilo :
I've been using a very similar solution, but it annoyed the hell out of me as it appeared flaky and unreliable.
Thank you for smartly pointing out everything that actually goes wrong with that "Save to a file" approach.
It's a relief to have someone of your caliber confirm that it was not only my programming that was at fault.
[Edit] Putting ShowDebugOutput() at the very start indeed does wonders. Nice find.
Seems to work perfectly (PB 5.31 x86 under Win 8.1 x64) so far. Thank you !
How did you just pull such a neat bit of magic out of your hat all of a sudden?
That's gotta be a mighty big hat you have there, or is it the head under the hat that is so big ?
I'll explore that mystery later, but for now, suffice it to say that your solution does wonders for my nerves.
When you're dealing with over 1000 lengthy lines of data per output, your solution is a major help and time saver.
@Danilo :
I've been using a very similar solution, but it annoyed the hell out of me as it appeared flaky and unreliable.
Thank you for smartly pointing out everything that actually goes wrong with that "Save to a file" approach.
It's a relief to have someone of your caliber confirm that it was not only my programming that was at fault.
[Edit] Putting ShowDebugOutput() at the very start indeed does wonders. Nice find.
PB Forums : Proof positive that 2 heads (or more...) are better than one 

Re: Programmatically send the DebugOutput to the ClipBoard
Having both Netmaestro and Danilo on the PureBasic forums allows me to sleep very, very well. 

- It was too lonely at the top.
System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem