This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
vba:functions:arrayshift [03.07.2014 11:50:31] yaslaw |
vba:functions:arrayshift [08.07.2014 11:54:43] (current) yaslaw [[VBA] arrayShift()] |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== [VBA] arrayShift() ====== | ====== [VBA] arrayShift() ====== | ||
Analog zu array_shift() aus PHP. Der erste Wert wird zurückgegeben und aus dem Array entfernt | Analog zu array_shift() aus PHP. Der erste Wert wird zurückgegeben und aus dem Array entfernt | ||
+ | |||
Liefert den ersten Wert von array , verschiebt die anderen Werte hinunter, und verkürzt array um ein Element. | Liefert den ersten Wert von array , verschiebt die anderen Werte hinunter, und verkürzt array um ein Element. | ||
Alle numerischen Schlüssel werden so modifiziert, dass bei null zu zählen begonnen wird. | Alle numerischen Schlüssel werden so modifiziert, dass bei null zu zählen begonnen wird. | ||
Ist array leer (oder kein Array), wird NULL zurückgegeben. | Ist array leer (oder kein Array), wird NULL zurückgegeben. | ||
+ | |||
Wenn man den Returnwert als 2ten Paramater abgreift, muss man sich nicht mehr darum kümmern, ob er ein Objekt ist oder nicht. | Wenn man den Returnwert als 2ten Paramater abgreift, muss man sich nicht mehr darum kümmern, ob er ein Objekt ist oder nicht. | ||
Will man das nicht, kann auch der Boolean-Parameter um den IndexReset zu steuern an 2ter Stelle mitgeben. Ist als oValue mit einem | Will man das nicht, kann auch der Boolean-Parameter um den IndexReset zu steuern an 2ter Stelle mitgeben. Ist als oValue mit einem | ||
Boolean belegt, dann wird das als iIndexReset intepretiert | Boolean belegt, dann wird das als iIndexReset intepretiert | ||
+ | {{:vba:functions:udf_arrayshift.bas|Download udf_arrayshift.bas}} | ||
===== Definition ===== | ===== Definition ===== | ||
<code>value = arrayShift(array [,value][,indexReset]) | <code>value = arrayShift(array [,value][,indexReset]) | ||
Line 25: | Line 28: | ||
===== Beispiele ===== | ===== Beispiele ===== | ||
+ | > Für die Ausgabe der Resultate verwendete ich die Funktion [[vba:functions:print_r:index]] | ||
+ | |||
<code vb>value = arrayShift(values) 'Einfach erste rausnehmen | <code vb>value = arrayShift(values) 'Einfach erste rausnehmen | ||
arrayShift values, value 'dito | arrayShift values, value 'dito | ||
Line 32: | Line 37: | ||
arrayShift values, false 'Erster wird entfernt und weggeworfen, Index bleibt erhalten</code> | arrayShift values, false 'Erster wird entfernt und weggeworfen, Index bleibt erhalten</code> | ||
+ | ==== Normale anwendung ==== | ||
+ | <code vb>Public Sub testArrayShift() | ||
+ | Dim a As Variant: a = Array("a", "b", "c", "d") | ||
+ | Dim first As String: first = arrayShift(a) | ||
+ | | ||
+ | print_rm first, a | ||
+ | End Sub</code> | ||
+ | <code><String> a | ||
+ | <Variant()> ( | ||
+ | [0] => <String> b | ||
+ | [1] => <String> c | ||
+ | [2] => <String> d | ||
+ | )</code> | ||
+ | |||
+ | ==== Mit referenzierter Out-Variable, ohne rücksetzen des Index ==== | ||
+ | <code vb>Public Sub testArrayShift() | ||
+ | Dim a As Variant: a = Array(New regExp, New FileSystemObject, New Field) | ||
+ | Dim first As Object | ||
+ | | ||
+ | arrayShift a, first, False | ||
+ | | ||
+ | print_rm first, a | ||
+ | End Sub</code> | ||
+ | <code><IRegExp2> ( | ||
+ | [Pattern] => <String> | ||
+ | [Global] => <Boolean> False | ||
+ | [IgnoreCase] => <Boolean> False | ||
+ | [Multiline] => <Boolean> False | ||
+ | ) | ||
+ | <Variant()> ( | ||
+ | [1] => <FileSystemObject> | ||
+ | [2] => <Field2> ( | ||
+ | [OrdinalPosition] => <Integer> 0 | ||
+ | [name] => <String> | ||
+ | |||
+ | [type] => <Integer> 0 | ||
+ | ) | ||
+ | )</code> | ||
===== Code ===== | ===== Code ===== | ||
<code vb udf_arrayshift.bas>'------------------------------------------------------------------------------- | <code vb udf_arrayshift.bas>'------------------------------------------------------------------------------- |