Einfach einige Beispiele die ich im Direktfenster ausgeführt habe
print_r 123.4 <Double> 123.4 print_r 12345 <Integer> 12345 print_r "Hallo Welt " <String> 'Hallo Welt ' print_r NULL <Null> Print_r split("a b v") <String()> ( [0] => <String> 'a' [1] => <String> 'b' [2] => <String> 'v' )
Hier ein kleines Testbeispiel bei dem diverse verschiedene Typen ineinander verschachtelt sind
Public Sub testPrintR() Dim col As New Collection Dim dict As New Dictionary Dim arr(1) As Variant Dim FSO As New FileSystemObject 'Ein Array zusammenstellen arr(0) = "abc" arr(1) = 1345.43 'Ein Dictionaray zusammenstellen Call dict.add("a", "AAA") Call dict.add("int", 123) Call dict.add("dbl", 12.3) Call dict.add("arr", arr) Call dict.add("Null-Wert", Null) Call dict.add("Empty-Wert", Empty) Call dict.add("FSO", FSO) 'Und eine Collection Call col.add(Now()) Call col.add(dict) print_r col Set FSO = Nothing Set dict = Nothing Set col = Nothing End Sub
Und das ist die Ausgabe im Direkt-Fenster
<Collection> ( [1] => <Date> 29.10.2013 09:51:45 [2] => <Dictionary> ( [a] => <String> 'AAA' [int] => <Integer> 123 [dbl] => <Double> 12.3 [arr] => <Variant()> ( [0] => <String> 'abc' [1] => <Double> 1345.43 ) [Null-Wert] => <Null> [Empty-Wert] => <Empty> [FSO] => <FileSystemObject> ) )
Die ganzen MatchCollection, Match und Submatches können einfach über print_r ausgegeben werden
Public Sub testPrintRRegExp() Dim rx As New regExp rx.Pattern = "([a-c])#(\d+)" rx.Global = True 'Das Objekt rx analysieren print_r rx 'Und die Treffer print_r rx.execute("Wir haben die Schlüssel a#1, b#12 und c#9 zur Auswahl") Set rx = Nothing End Sub
<IRegExp2> ( [Pattern] => <String> '([a-c])#(\d+)' [Global] => <Boolean> True [IgnoreCase] => <Boolean> False [Multiline] => <Boolean> False ) <IMatchCollection2> ( [0] => <IMatch2> ( [Match] => <String> 'a#1' [FirstIndex] => <Long> 24 [SubMatches] => <ISubMatches> ( [0] => <String> 'a' [1] => <String> '1' ) ) [1] => <IMatch2> ( [Match] => <String> 'b#12' [FirstIndex] => <Long> 29 [SubMatches] => <ISubMatches> ( [0] => <String> 'b' [1] => <String> '12' ) ) [2] => <IMatch2> ( [Match] => <String> 'c#9' [FirstIndex] => <Long> 38 [SubMatches] => <ISubMatches> ( [0] => <String> 'c' [1] => <String> '9' ) ) )
Dim a(1, 1, 1) As Integer a(0, 0, 0) = 0 a(0, 0, 1) = 1 a(0, 1, 0) = 2 a(0, 1, 1) = 3 a(1, 0, 0) = 4 a(1, 0, 1) = 5 a(1, 1, 0) = 6 a(1, 1, 1) = 7 print_r a
ergibt
<Integer()> ( [0.0.0] => <Integer> 0 [0.0.1] => <Integer> 1 [0.1.0] => <Integer> 2 [0.1.1] => <Integer> 3 [1.0.0] => <Integer> 4 [1.0.1] => <Integer> 5 [1.1.0] => <Integer> 6 [1.1.1] => <Integer> 7 )
Als erstes mal ein kleines Klassenmodul mit 3 Properties. Nachname und Vorname als Get und Set. Dazu noch Name nur als Get, da dieser aus Vor- und Nachname zusammengesetzt ist.
Option Compare Database Private pVorname As String Private pNachname As String Public Property Get nachname() As String nachname = pNachname End Property Public Property Let nachname(ByVal vNewValue As String) pNachname = vNewValue End Property Public Property Get vorname() As String vorname = pVorname End Property Public Property Let vorname(ByVal vNewValue As String) pVorname = vNewValue End Property Public Property Get name() As String name = vorname & " " & nachname End Property
Dann mal ein kleines Testscript
Dim yaslaw As New TestClass yaslaw.vorname = "Yaslaw" yaslaw.nachname = "Kowalejeff" print_r yaslaw
Und so sieht es dann aus
<Class Module::TEstClass> ( [nachname] => <String> 'Kowalejeff' [vorname] => <String> 'Yaslaw' [name] => <String> 'Yaslaw Kowalejeff' )
Das ist die Standarteinstellung
print_r 123 print_r 123, prConsole
Dim txt as String txt = print_r(123, prReturn)
print_r 123, prConsole + prClipboard
print_rm "Hallo Welt", strToDate("01022013", "mmddyyyy"), split("1,2,3", ",") <String> 'Hallo Welt' <Date> 02.01.2013 <String()> ( [0] => <String> '1' [1] => <String> '2' [2] => <String> '3' )
'Standart mit Tabulator und Nicht druckbaren Leerzeichen print_r chr(29) & " A " & vbTab & " B " & chr(1) & " C" <String> '\u001D A \t B \u0001 C' 'Dito, aber ohne ersetzen des Tabulators print_r chr(29) & " A " & vbTab & " B " & chr(1) & " C", -prEscapeSpaces <String> '\u001D A B \u0001 C' 'Ausgabe von Zahlen und Texten ohne Anfühurnungszeichen print_r Array("a", "b" & vbTab & "c", 101), -prStringSingleQuotes <Variant()> ( [0] => <String> a [1] => <String> b\tc [2] => <Integer> 101 ) 'Ditp, mit Dippoelten Anführungszeichen print_r Array("a", "b" & vbTab & "c", 101), prParamsDefault -prStringSingleQuotes + prStringDoubleQuotes <Variant()> ( [0] => <String> "a" [1] => <String> "b\tc" [2] => <Integer> 101 ) 'Ausgabe ohne weitere formatierung print_r Array("a", "b" & vbTab & "c", 101), prNoParams ( [0] => a [1] => b c [2] => 101 ) 'Ausgabe eines Strings mit doppelten Anführungszeichen zur Weiterverarbeitung print_r "abc(""Hallo Welt"& chr(34) & ")", prEscapeDoubleQuotes+prStringDoubleQuotes "abc(""Hallo Welt"")"
'Text mit leerzeichen am Schluss. Das ist bei debug.print nichterkennbar ? "Hallo Welt " Hallo Welt 'Beim print_r() hingegen schon d "Hallo Welt " <String> 'Hallo Welt ' 'Und dasselbe mit nicht angezeigten Spezialteichen ? "Hallo Welt" & chr(1) Hallo Welt d "Hallo Welt" & chr(1) <String> 'Hallo Welt\u0001'
Für diesen Test verwende ich die Cast-Funktionen von [VBA] JSON
'Normale Ausgabe im ImmadiateWindow ? obj2json(array(1, "a", "c""d", array(4, 5))) [1,"a","c\"d",[4,5]] 'Normaler print_r(). In dem Fall über den Alias d() d obj2json(array(1, "a", "c""d", array(4, 5))) <String> '[1,"a","c\"d",[4,5]]' 'Und zur Codeweiterverarbeitung geeignet c obj2json(array(1, "a", "c""d", array(4, 5))) "[1,""a"",""c\""d"",[4,5]]" 'Ausgabe direkt kopiert zum weitertesten d json2obj("[1,""a"",""c\""d"",[4,5]]", jrtArray) <Variant()> ( [0] => <Byte> 1 [1] => <String> 'a' [2] => <String> 'c"d' [3] => <Variant()> ( [0] => <Byte> 4 [1] => <Byte> 5 ) )