VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



First time ever Clear the Debug/Immediate window with code

by José Lucio Gama (1 Submission)
Category: Debugging and Error Handling
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (4 Votes)

For the first time ever, a code that can clear the debug window from code!
It's actually a cheat, since VB5-VB6 doesn't allow to clear the window without stopping the running project - the program sets the focus on the debug window, go to the last char and start printing a lot of empty lines - effectively getting rid of all clutter visible on the window.

Assumes
Win32 API knowledge
API Declarations
FindWindow, SetForegroundWindow and SetFocus

Rate First time ever Clear the Debug/Immediate window with code

Put this on the top of your form:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetFocusAPI Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
Then, paste this on your code:
Private Sub clearDebug()
  'this will try to get the handle to your
  'Immediate window. To make this work on
  'VB4, you can change the string "Immediate"
  'to "Debug"
  parent_hwnd = FindWindow(vbNullString, "Immediate")
  If parent_hwnd = 0 Then Exit Sub
  ' Set the focus on the debug window
  SetFocusAPI parent_hwnd
  'go to the last line / position on the window
  '(same as pressing CTRL + END on your keyboard
  SendKeys "^{END}", True
  
  'you can adjust the number of lines
  'printed according to your Immediate 
  'window size
  For i = 1 To 100
    Debug.Print ""
  Next
  
  'give the focus back to your program!
  SetForegroundWindow Me.hwnd
End Sub
Then just call clearDebug() anywhere in your code  and that it!

Download this snippet    Add to My Saved Code

First time ever Clear the Debug/Immediate window with code Comments

No comments have been posted about First time ever Clear the Debug/Immediate window with code. Why not be the first to post a comment about First time ever Clear the Debug/Immediate window with code.

Post your comment

Subject:
Message:
0/1000 characters