Link to home
Start Free TrialLog in
Avatar of lankford
lankford

asked on

vb6: Programatically Clear Immediate Window

That's it.  How do you clear the Immediate Window from code?  I can debug.print to it all day long, but I want to be able to clear it from time to time.  Did Microsoft provide us with a feature to do this?

Thanks,

Lankford
Avatar of caraf_g
caraf_g

Good question, I've often wondered why there is no debug.clear method.

Hope you don't mind I hitch a ride on this one ;-)
Well . . . what I always do is periodically select all the text and hit the delete key.  But I assume that's not the answer you're looking for.  There might be a way to do it by subclassing the IDE, but that's something I haven't done anything with myself so far.
This question has been asked a couple of times, and no one has come up with a good answer...

The hoaky solution I've seen posted here is:

for i=1 to 200
   debug.print VbCrLF
next i


That doesn't clear the window, but it will give the "appearance" of an empty window...


Lame huh?
                   Public Sub ClearDebug()
                   

                       Dim pWindow As VBIDE.Window
                       
              Set pWindow = VBInstance.Windows("Immediate")
                       
                       If pWindow Is Nothing Then Exit Sub
                       
                       If pWindow.Visible = True Then
                          pWindow.SetFocus
                          SendKeys ("^({Home})"), True
                          SendKeys ("^(+({End}))"), True
                          SendKeys ("{Del}"), True
                       End If
                       Set pWindow = Nothing

                    End Sub
Nicely done, Deighton :-)
Making it an Add-In will keep it out of your code.
deighton,

What reference do you have to add in to get "Dim pWindow As VBIDE.Window" to work?

Cheers!
no shame deighton, its not "What you know", but "Who you know" LOL
Avatar of lankford

ASKER

All right.  I'm totally confused now.  What are we saying here people?  You have to have Waty's add-in in order to do this.  I downloaded/installed the add-in but all I get is a button that perfoms this function in design mode.  How do you call this function from your code?  Can you?

lankford (dazed and confused)
I just saw Eric's response.  I am rejecting this answer because you apparently can't call it from code.

So far, mcrider is the closest!

lankford
deighton,
 
So there is no reference to add?? or this only works on VB6?

Cheers!

You need to add a reference to VB6 Extensibility
I can't get it to work with VB5 Extensibility...
The "hoaky" and "lame" answer is also a valid one, kiddies. The debug window has a limit on the number of lines it contains. Filling it with empty lines does not just give the appearance of clearing it, it actually does. Empty strings replace populated ones.... out with the old , in the new. <G>

mdrider,

In the interest of closing out this topic, convert your comment into an answer and I'll award you the points.

lankford
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
DrDelphi,

By the way, it doesn't work if the last cursor position of the immediate window is at the top of the window...

Cheers!
McRider,
  If the cursor position is at the top of the window, what are you trying to clear? <G>
DrDelphi,

Ok, your program puts 60 or so lines in the debug box... your Immediate window has been sized to show about 10 lines at a time... You focus in the Immediate window with your cursor and use the arrow keys or PageUP keys to scroll up to the top of the immediate window to see the 1st 10 lines your program put there.

Then you want to clear the window... Run the code and see what happens...

Cheers!
Thanks for the points!
This message is for mcrider more than anyone......

I found something that clears the immediate window for you ..
a VB Pligin (with source)

i've not tested it yet though

What was the other message we were trying to do this in mcrider ?

Here's the URL : http://vbcode.com/asp/showzip.asp?ZipFile=http://www.vbcode.com/code/Clearlmm.zip&theID=736