This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
vba:functions:printlist [24.02.2016 12:57:00] yaslaw created |
vba:functions:printlist [04.09.2019 11:56:42] (current) yaslaw |
||
---|---|---|---|
Line 1: | Line 1: | ||
<const> | <const> | ||
- | version=1.0.0 | + | version=1.1.1 |
- | vdate=02.02.2016 | + | vdate=04.09.2019 |
fname=udf_printlist.bas | fname=udf_printlist.bas | ||
ns=%NAMESPACE% | ns=%NAMESPACE% | ||
Line 14: | Line 14: | ||
>Siehe auch [[vba:functions:printref]] | >Siehe auch [[vba:functions:printref]] | ||
+ | |||
+ | ===== Beschreibung ===== | ||
+ | Mit dieser Methode kann eine Liste sauber ausgegeben werden- Ich verwende sie zum Beispiel für die Methode [[vba:functions:printref]]. | ||
+ | |||
+ | ===== Definitionen ===== | ||
+ | <code>printList(DataArray [,HeaderArray [,ReturnOptionen [,FormatArray]]])</code> | ||
+ | <code vb>Public Function printList( _ | ||
+ | ByRef iData As Variant, _ | ||
+ | Optional ByRef iHeader As Variant = Null, _ | ||
+ | Optional ByVal iReturn As enuPrintListOutputMethode = prListConsole, _ | ||
+ | Optional ByRef iFormats As Variant = Null _ | ||
+ | ) As String</code> | ||
+ | |||
+ | ***iData** Array<Array<Variant>> Ein verschachtelter Array. Array<Zeilen<Werte>> | ||
+ | ***iHeader** Array<String> Ein Array mit dem Header | ||
+ | ***iReturn** enuPrintListOutputMethode Art der Rückgabe: Standart ist das Direktfenster. Alternativ kann man auch als Rückgabewert der Funktion oder in den Zwieschnepseicher des PCs schreiben. Die Auswahlen lassen sich auch kombinieren: prConsole+prClipboard | ||
+ | ***iFormats** Ein Array mit dFormaten um die Daten zu formatieren. Siehe auch format() von VBA | ||
+ | ***Return** String Resultat oder Fehlermeldung | ||
+ | |||
+ | ==== Enumerator ==== | ||
+ | === enuPrintListOutputMethode === | ||
+ | |||
+ | Auswahl was mir der Analyse geschehen soll. Die Werte lassen sich mit + kombinieren | ||
+ | ***prListConsole**(1) Die Ausgabe wird ins Direktfenster geschrieben | ||
+ | ***prListReturn**(2) Die Ausgabe wird als Funktionsrückgabewert zurückgegeben | ||
+ | ***prListClipboard**(4) Die Ausgabe wird in den Zwieschenspeicher geschrieben | ||
+ | ***prListMsgBox**(8) Die Ausgabe wird als Popup ausgegeben | ||
+ | | ||
+ | ===== Settings ===== | ||
+ | Das Modul hat eine Kompilierbedinung. MS Access kennt den Befehl NZ(), MS Excel kennt den nicht. Um in Excel den Befehl zu verwenden habe ich die NZ-Funktion nachgebaut und in eine Bedingte Komplilierung gesetzt. Darum muss am Anfang vom Code eingestellt werden, ob der CODE unter MS Access läuft oder nicht | ||
+ | |||
+ | <code vb>'------------------------------------------------------------------------------- | ||
+ | ' -- ! SETTINGS ! | ||
+ | '------------------------------------------------------------------------------- | ||
+ | 'In Excel funktionieren Events nicht. Auch der NZ() gibt es dort nicht. | ||
+ | 'Darum hier angeben ob es sich um MS Access handelt oder eben nicht. Leider gibts datzu keine Systemvariable | ||
+ | #Const isAccess = True | ||
+ | |||
+ | .... | ||
+ | |||
+ | #If Not isAccess Then | ||
+ | '/** | ||
+ | ' * Wandelt NULL in EMpty oder einen Defaultwert | ||
+ | ' * @param Variant | ||
+ | ' * @param Variant | ||
+ | ' * @return Variant | ||
+ | ' */ | ||
+ | Private Function NZ(ByRef iValue As Variant, Optional ByRef iDefault As Variant = Empty) As Variant | ||
+ | If IsNull(iValue) Then | ||
+ | NZ = iDefault | ||
+ | Else | ||
+ | NZ = iValue | ||
+ | End If | ||
+ | End Function | ||
+ | #End If</code> | ||
===== Beispiele ===== | ===== Beispiele ===== | ||
+ | Das Beispiel macht so natürlich keinen Sinn, zeigt aber wie der Aufbaeu der Parameter sein muss | ||
+ | <code vb>printlist array(array(1,2,3, date()), array(11,22,33, date()+1)), array("A", "B", "C", "D") | ||
+ | A | B | C | D | ||
+ | ---|----|----|----------- | ||
+ | 1 | 2 | 3 | 29.02.2016 | ||
+ | 11 | 22 | 33 | 01.03.2016</code> | ||
+ | |||
+ | Ein Beispiel ohne Header, dafür ist die 2te Spalte formatiert | ||
+ | <code vb>printlist array(array(1, 2, "abc"), array(1.5, 2345.6, null)),,,array(,"#,##0.00") | ||
+ | 1 | 2.00 | abc | ||
+ | 1.5 | 2'345.60 | </code> | ||
+ | Einweiteres Beispiel ist die Funktion [[vba:functions:printref]]. | ||
===== Code ===== | ===== Code ===== | ||
<source '%%fpath%%/%%fname%%' vb> | <source '%%fpath%%/%%fname%%' vb> |