In VBA Debug.Print prints to the Immediate window.
I just found out that using a semicolon (;) makes it print at the position of the caret/text cursor which seems odd.
Debug.Print "a" & "b" & "c"
Debug.Print ; "a"; "b"; "c"
Debug.Print "a", "b", "c"
Prints the following.
abc
abc
a b c
That was my main question before I found it in the documentation and understood it a little more.
My question now is if it is possible to use a named argument like this:
Debug.Print object:="..."
Intellisense usually helps finding the arguments' names but it doesn't list any.
I also tried object or outputlist like it shows in the docs but it throws an error.
Is Debug.Print different in that regard?
Debugstatements are indeed different from everything else. If you look for aDebugmodule in the Object Browser, you won't find it, even with hidden classes and members shown.Debug.PrintandDebug.Assertstatements are literally baked into the language [parser] itself - the comma here doesn't mean "argument separator", instead it's a special-form syntax that is [apparently] reserved forPrintmethods (note: VBA user code cannot usePrintfor a method name, it's reserved).So
Debugstatements are basically special kinds of keywords. IntelliSense / parameter quick-info is shown for argument list syntax elements, but syntactically, the "arguments" of aDebug.Printare an output list, exactly like the Print statement does.Note that the VBE automatically turns a
?token into aPrintstatement:There's quite a bit of historical baggage with
Print: the keyword/command (and its?shorthand) was used in old BASIC dialects to output things to a screen... or an actual [dot matrix!] printer.So the short answer is,
Debugstatements are made with keywords, not member calls - and that's why IntelliSense isn't of any use with them, since there aren't any arguments.The Rubberduck project has a fun story with these statements... because it isn't really possible to parse a typical
Debug.Printstatement any differently than any other implicitcallStmt(i.e. it looks and parses like any other procedure call), we had to give the statement its own dedicated parser rule, and "declare" a fakeDebugClassmodule and makePrinta "method" of that "class" in order to be able to track uses like we do with other early-bound identifier references:But there really isn't such a thing: statements with an output list are baked into the language at the parser & compiler level, whereas literally every other member call you ever made in VBA was a member of some module - hit F2 and browse the members of the VBA standard library: you'll find
CLngtype conversion,NowandDateAdddate/time functions,MsgBox,DoEvents, and so many others - all belong to some module. ButDebugstatements are closer to aStoporResumekeyword, handled at a lower level.Further proof that there's more than meets the eyes - other than the simple fact that default syntax highlighting in the VBE will highlight both
DebugandPrintin bright keyword-blue, if you compile a COM-visible class written in C#:..and then invoke it from VBA code...
The
DoSomethingmethod can be invoked, but thePrintmethod will throw error 438 - just like it would if you tried to qualify it with anything other thanDebug. So how comePrintworks in an Access report's code-behind then?The interface isn't documented so this is pure speculation, but there's an
IVBPrintinterface that looks very much like something VBA would be looking for:If that's the case, then error 438 is just VBA's way to say "IVBPrint implementation not found"