User Tools

Site Tools


vba:functions:list

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
vba:functions:list [26.05.2014 10:59:20]
yaslaw
vba:functions:list [06.03.2019 08:35:23] (current)
yaslaw [[VBA] list()]
Line 1: Line 1:
 +<​const>​
 +    version=1.1.1
 +    vdate=09.10.2015
 +    fname=udf_list.bas
 +    ns=%NAMESPACE%
 +    fpath=/​vba/​functions
 +</​const>​
 +{{keywords>​vba,​list,​array}}
 +{{description>​Diese Funktionen schreiben die Werte einer Auflistung in Variablen. Fast so wie list() in PHP. V-%%version
 +%%}}
 +
 ====== [VBA] list() ====== ====== [VBA] list() ======
-Diese Funktionen schreiben ​die Werte einer Auflistung in Variablen. Fast so wie list() in PHP. +//Diese Funktion schreibt ​die Werte einer Auflistung in Variablen. Fast so wie list() in PHP. 
-\\ list() ist geeignet um ein Array, Collection etc. in Variablen zu zerteilen.+list() ist geeignet um ein Array, Collection etc. in Variablen zu zerteilen.
  
 +//==Version %%version%% %%vdate%%==
 +{{%%fname%%|Download %%fname%% (V-%%version%%)}}
  
 Dieselbe Technik verende ich auch bei der Klasse [[:​vba:​classes:​iterator:​]]. Dieselbe Technik verende ich auch bei der Klasse [[:​vba:​classes:​iterator:​]].
Line 116: Line 129:
 4: 7 + 5 = 12</​code>​ 4: 7 + 5 = 12</​code>​
 ===== Code ===== ===== Code =====
-<code vb listFunc.bas>​ +<source ​'%%fpath%%/%%fname%%' ​vb>
-'------------------------------------------------------------------------------- +
-'​File ​        : ListFunc +
-' ​              ​Copyright mpl by ERB software +
-' ​              All rights reserved +
-' ​              http://​wiki.yaslaw.info/​dokuwiki/​doku.php/​vba/​functions/​list +
-'Environment ​ : VBA 2010 + +
-'​Version ​     : 1.0 +
-'​Name ​        : list +
-'​Author ​      : Stefan Erb (ERS) +
-'​History ​     : 27.02.2014 - ERS - Creation +
-'​------------------------------------------------------------------------------- +
-Option Explicit +
- +
-Public Const LIST_ERR_NO_PARAMS = vbObjectError + 5000 +
- +
-'/** +
-' * Dito zu List. Aber die Argumente ist ein vordimensionierter Array +
-' * @param ​ Liste           ​Array,​ Dictionary, Collection, Regexp.MatchCollection,​ Regexp.Match oder DAO.Recordset +
-' * @param ​ Array<​Varaint> ​ Auflistung der Variablen, die abgefüllt werden +
-' * @return Boolean ​        ​Angabe,​ ob die ganze Sache gültig war +
-' */ +
-Public Function list( _ +
-        ByRef iList, _ +
-        ParamArray oParams() As Variant _ +
-) As Boolean +
-    Dim lBnd    As Long:    lBnd = 0 +
-    Dim uBnd    As Long:    uBnd = UBound(oParams) +
-    Dim i       As Long +
-On Error GoTo Err_Handler +
-     +
-    If uBnd = -1 Then Err.Raise LIST_ERR_NO_PARAMS,​ "​list",​ "No Parameters"​ +
-     +
-    '​Array +
-    If IsArray(iList) Then +
-        If lBnd < LBound(iList) Then lBnd = LBound(iList) +
-        If uBnd + lBnd > UBound(iList) Then uBnd = UBound(iList) - lBnd +
-        list = True 'Bei einem nicht initialisertem Array generierendie vorherenden Zeilen bereits ein Fehler -> Code abgebrochen,​ Return: False +
-        For i = 0 To uBnd +
-            If isObject(iList(lBnd + i)) Then Set oParams(i) = iList(lBnd + i) Else oParams(i) = iList(lBnd + i) +
-        Next +
-    '​Dictionary +
-    ElseIf TypeName(iList) = "​Dictionary"​ Then +
-        list = iList.count > 0:     If Not list Then Exit Function +
-        Dim keys  As Variant: ​  keys = iList.keys +
-        If uBnd > iList.count - 1 Then uBnd = iList.count - 1 +
-        For i = 0 To uBnd +
-            If isObject(iList(keys(i))) Then Set oParams(i) = iList(keys(i)) Else oParams(i) = iList(keys(i)) +
-        Next i +
-    '​Collection +
-    ElseIf TypeName(iList) = "​Collection"​ Then +
-        list = iList.count > 0:     If Not list Then Exit Function +
-        If uBnd > iList.count - 1 Then uBnd = iList.count - 1 +
-        For i = 0 To uBnd +
-            If isObject(iList(i + 1)) Then Set oParams(i) = iList(i + 1) Else oParams(i) = iList(i + 1) +
-        Next i +
-    '​MatchCollection +
-    ElseIf TypeName(iList) = "​IMatchCollection2"​ Then +
-        list = iList.count > 0:     If Not list Then Exit Function +
-        If uBnd > iList.count - 1 Then uBnd = iList.count - 1 +
-        For i = 0 To uBnd +
-            oParams(i) = iList(i).value +
-        Next i +
-    '​Match +
-    ElseIf TypeName(iList) = "​IMatch2"​ Then +
-        list = iList.SubMatches.count > 0:     If Not list Then Exit Function +
-        If uBnd > iList.SubMatches.count - 1 Then uBnd = iList.SubMatches.count - 1 +
-        For i = 0 To uBnd +
-            oParams(i) = iList.SubMatches(i) +
-        Next i +
-    '​Recorset +
-    ElseIf TypeName(iList) = "​Recordset2"​ Then +
-        list = Not iList.BOF And Not iList.EOF: If Not list Then Exit Function +
-        If uBnd > iList.fields.count - 1 Then uBnd = iList.fields.count - 1 +
-        For i = 0 To uBnd +
-            oParams(i) = iList(i) +
-        Next i +
-    End If +
-     +
-Exit_Handler:​ +
-    Exit Function +
-Err_Handler:​ +
-    list = False +
-    GoSub Exit_Handler +
-End Function +
-</code>+
vba/functions/list.1401094760.txt.gz · Last modified: 26.05.2014 10:59:20 by yaslaw