-
Feb 14th, 2012, 11:34 PM
#1
Thread Starter
New Member
[RESOLVED] How to clear Immediate Window in IDE
Can this be done with code from within the current project?
Jim
-
Feb 15th, 2012, 12:01 AM
#2
Re: How to clear Immediate Window in IDE
You cannot delete anything from the Immediate window while running mode, but only while stop or pause.
-
Feb 15th, 2012, 12:11 AM
#3
Re: How to clear Immediate Window in IDE
I don't think it's impossible, there must be way to do it at least pausing execution first (also by code), but the true is there hasn't been any direct solution for this. MZTools can do it but not at runtime.
Also there is this 4 year old thread with exactly the same topic: Clear Emmediate Window where i've been trying to do it by code with partial success, i'll play a bit now with that code again, who knows.
Edgemeal also provided a solution in that thread but it's not working for me.
Last edited by jcis; Feb 15th, 2012 at 12:16 AM.
-
Feb 15th, 2012, 12:42 AM
#4
Thread Starter
New Member
Re: How to clear Immediate Window in IDE
Thanks for replies. Looked at the old thread. Damn!! Wouldn't Debug.Cls be handy!!!
I do not think that the Immediate window can be disabled while running a project, after all Debug.Print still works.!
Perhaps I'll try Module Subs MyDebugPrint and MyDebugCls to work on a frmDebug with a Scrolable Picture or RTB???
Sound daft?
Jim
-
Feb 15th, 2012, 12:45 AM
#5
Re: How to clear Immediate Window in IDE
Debug.Cls probably doesn't exist for a good reason, after all that window is meant as a debugging log.
I do wish the window was cleared each run though. At least there are add-ins that can do that much for us.
-
Feb 15th, 2012, 01:24 AM
#6
Re: How to clear Immediate Window in IDE
I can't believe it, i think i've got it. Just playing with my old attempt in that thread then changed to keybd_event API. Use your inmediate window caption as last param when calling FindWindowEx, i'm not sure but in english it should be "Inmediate".
Code:
Option Explicit
Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "User32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Private Declare Function PostMessage Lib "User32" Alias "PostMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Declare Sub keybd_event Lib "User32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const WM_ACTIVATE As Long = &H6
Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_CANCEL = &H3
Private Const VK_CONTROL = &H11
Private Sub ClearInmediateWindow()
Dim lWinVB As Long, lWinEmmediate As Long
lWinVB = FindWindow("wndclass_desked_gsk", vbNullString)
'Last param depends on languages, use your inmediate window caption:
lWinEmmediate = FindWindowEx(lWinVB, ByVal 0&, "VbaWindow", "Immediate")
PostMessage lWinEmmediate, WM_ACTIVATE, 1, 0&
keybd_event VK_CANCEL, 0, 0, 0 ' (This is Control-Break)
keybd_event VK_CONTROL, 0, 0, 0 'Select All
keybd_event vbKeyA, 0, 0, 0 'Select All
keybd_event vbKeyDelete, 0, 0, 0 'Clear
keybd_event vbKeyA, 0, KEYEVENTF_KEYUP, 0
keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0
keybd_event vbKeyF5, 0, 0, 0 'Continue execution
keybd_event vbKeyF5, 0, KEYEVENTF_KEYUP, 0
End Sub
You can call ClearInmediateWindow at runtime (for example in a button event) or as last line in Form_Load, it will pause execution, clear the inmediate window and then continue execution.
For testing pourposes you can also add another button to fill your inmediate window, like..
Code:
Private Sub Command2_Click()
Dim i As Long
For i = 0 To 1000
Debug.Print "TEST!!!! Number: " & i
Next
End Sub
Last edited by jcis; Feb 15th, 2012 at 02:36 AM.
-
Feb 15th, 2012, 01:46 AM
#7
Thread Starter
New Member
Re: How to clear Immediate Window in IDE
JCIS that works fine for me. Just one spelling change for my location --- Immediate for Inmediate.
Many many thanks
Jim
-
Feb 15th, 2012, 02:33 AM
#8
Re: How to clear Immediate Window in IDE
Originally Posted by AussieJim
JCIS that works fine for me. Just one spelling change for my location --- Immediate for Inmediate.
Ok, i corrected that in my previous post.
The only limitation i see till now: the call to ClearInmediateWindow() shouldn't be mixed with your code, it should be alone, i mean for example an event (as a button click event) or as last line inside an event/sub with more code, like Form_Load. the Form should always get focus after ClearInmediateWindow() is executed or else some weird things may happen, like your own vb code being affected by that "Select all" inside ClearInmediateWindow().
-
Feb 15th, 2012, 02:40 AM
#9
Thread Starter
New Member
Re: [RESOLVED] How to clear Immediate Window in IDE
Also noticed that the current active form also gets a paint event fired
-
Feb 15th, 2012, 02:47 AM
#10
Re: [RESOLVED] How to clear Immediate Window in IDE
Originally Posted by AussieJim
Also noticed that the current active form also gets a paint event fired
Yes, that's ok. It happens because the Form loses focus for a moment while the immediate window get focus to be cleared. It's like minimizing your Form and then bringing it back, when your Form gets focus back Paint() event is always executed. Anyway, if you want you can also keep execution in break mode after calling ClearInmediateWindow() by removing last 2 lines in this sub.
Last edited by jcis; Feb 15th, 2012 at 02:54 AM.
-
Feb 19th, 2012, 05:04 PM
#11
Re: [RESOLVED] How to clear Immediate Window in IDE
Wow thanks jcis! Had given up on that a while ago after a fiasco trying to use the VBIDE object.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|