ScriptForge.Array service

Provides a collection of methods for manipulating and transforming arrays of one dimension (vectors) and arrays of two dimensions (matrices). This includes set operations, sorting, importing to and exporting from text files.

Voor arrays met meer dan twee dimensies kunnen deze methoden niet worden gebruikt, hierop is één uitzondering, de methode CountDims.

Een item in een array kan elke waarde bevatten, ook een array.

Service-aanroep

Voordat de service Array gebruikt kan worden moet ScriptForge bibliotheek worden geladen met:


      GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
   

Door het laden van de bibliotheek wordt een object SF_Array aangemaakt dat gebruikt kan worden voor het aanroepen van de methoden van de service Array.

De volgende stukjes code tonen manieren om de methoden aan te roepen in de service Array (de methode Append dient als voorbeeld):


      SF_Array.Append(...)
   

      Dim arr    :    arr = SF_Array
      arr.Append(...)
   

      Dim arr    :    arr = CreateScriptService("Array")
      arr.Append(...)
   
note

De methode CreateScriptService is pas beschikbaar na het laden van de bibliotheek ScriptForge.


Methoden

Append
AppendColumn
AppendRow
Contains
ConvertToDictionary
CountDims
Difference
ExportToTextFile
ExtractColumn
ExtractRow

Flatten
ImportFromCSVFile
IndexOf
Insert
InsertSorted
Intersection
Join2D
Prepend
PrependColumn
PrependRow

RangeInit
Reverse
Shuffle
Slice
Sort
SortColumns
SortRows
Transpose
TrimArray
Union
Unique


tip

Het eerste argument van de meeste methoden is het te beschouwen array-object. Het wordt bij referentie doorgegeven en het wordt niet gewijzigd. Methoden zoals Append, Prepend, enz geven na uitvoering een nieuw object terug.


Append

Voegt de genoemde items als argumenten toe aan het invoer-matrix.

Syntaxis:


      SF_Array.Append(Array_1D As Variant, arg0 As Variant, [arg1 As Variant], ...) As Variant
   

Parameters:

Array_1D : het vooraf bestaande array, dit kan leeg zijn.

arg0, ... : een lijst met argumenten die aan Array_1D toegevoegd gaan worden.

Voorbeeld:


      Sub Example_Append()
      Dim a As Variant
          a = SF_Array.Append(Array(1, 2, 3), 4, 5)
              ' (1, 2, 3, 4, 5)
      End Sub
   

AppendColumn

Voegt een kolom toe aan de rechterzijde van een tweedimensionale matrix. De nieuwe matrix heeft dezelfde ondergrens als het oorspronkelijke tweedimensionale matrix.

Syntaxis:


      SF_Array.AppendColumn(Array_2D As Variant, New_Column As Variant) As Variant
   

Parameters:

Array_2D : het bestaande array, dit kan leeg zijn. Als het array maar een dimensie heeft, dan wordt het beschouwd als de eerste kolom van het resulterende tweedimensionale array.

New_Column : een eendimensionaal array met evenveel items als dat er rijen zijn in Array_2D.

Voorbeeld:


      Sub Example_AppendColumn()
      Dim a As Variant, b As variant
          a = SF_Array.AppendColumn(Array(1, 2, 3), Array(4, 5, 6))
              ' ((1, 4), (2, 5), (3, 6))
          b = SF_Array.AppendColumn(a, Array(7, 8, 9))
              ' ((1, 4, 7), (2, 5, 8), (3, 6, 9))
          c = SF_Array.AppendColumn(Array(), Array(1, 2, 3))
              ' ∀ i ∈ {0 ≤ i ≤ 2} : b(0, i) ≡ i
      End Sub
   

AppendRow

Voegt aan de onderkant van een tweedimensionale matrix een nieuwe regel toe. De resulterende matrix heeft dezelfde ondergrens.

Syntaxis:


      SF_Array.AppendRow(Array_2D As Variant, Row As Variant) As Variant
   

Parameters:

Array_2D : het al bestaande array kan leeg zijn. Als het een eendimensionaal array is, dan wordt het gezien als de eerste rij van het resulterende tweedimensionale array.

Row : een eendimensionaal array met evenveel items als het aantal kolommen in het Array_2D.

Voorbeeld:


      Sub Example_AppendRow()
      Dim a As Variant, b As variant
          a = SF_Array.AppendRow(Array(1, 2, 3), Array(4, 5, 6))
              '  ((1, 2, 3), (4, 5, 6))
          b = SF_Array..AppendRow(Array(), Array(1, 2, 3))
              ' ∀ i ∈ {0 ≤ i ≤ 2} : b(i, 0) ≡ i
      End Sub
   

Contains

Controleert of een eendimensionale matrix een bepaald getal, tekst of datum bevat. De tekstvergelijking kan wel/niet hoofdletterafhankelijk zijn.
Gesorteerde invoer-matrixen moeten op dezelfde manier zijn gevuld, dat betekent dat alle items van hetzelfde type moeten zijn (Lege en Null items zijn niet toegestaan).
Het resultaat van de methode is onvoorspelbaar als u aangeeft dat het een gesorteerd matrix is en het is het niet.
Als het een gesorteerde matrix is wordt er een binaire zoek gedaan, in het andere geval wordt het hele matrix doorlopen waarbij items die leeg of Null zijn worden overgeslagen.

Syntaxis:


      SF_Array.Contains(Array_1D, ToFind As Variant, [CaseSensitive As Boolean], [SortOrder As String]) As Boolean
   

Parameters:

Array_1D : de te doorzoeken matrix.

ZoekNaar : een getal, een datum of een tekst waarnaar gezocht moet worden.

Hoofdletterafhankelijk : Alleen voor het vergelijken van teksten, standaard is False.

SortOrder : "ASC", "DESC" of "" (= niet gesorteerd, de standaard)

Voorbeeld:


      Sub Example_Contains()
      Dim a As Variant
          a = SF_Array.Contains(Array("A","B","c","D"), "C", SortOrder := "ASC") ' True
          SF_Array.Contains(Array("A","B","c","D"), "C", CaseSensitive := True) ' False
      End Sub
   

ConvertToDictionary

Sla de inhoud van een tweedimensionale matrix op in een ScriptForge.bibiotheek-object.
De sleutel wordt bepaald uit de eerste kolom, het item uit de tweede kolom.

Syntaxis:


      SF_Array.ConvertToDictionary(Array_2D As Variant) As Variant
   

Parameters:

Array_1D : de eerste kolom moet alleen teksten bevatten met een lengte groter dan 0, de volgorde is niet van belang.

Voorbeeld:


      Sub Example_ConvertToDictionary()
      Dim a As Variant, b As Variant
          a = SF_Array.AppendColumn(Array("a", "b", "c"), Array(1, 2, 3))
          b = SF_Array.ConvertToDictionary(a)
          MsgBox b.Item("c") ' 3
      End Sub
   

CountDims

Count the number of dimensions of an array. The result can be greater than two.
If the argument is not an array, returns -1
If the array is not initialized, returns 0.

Syntaxis:


      SF_Array.CountDims(Array_ND As Variant) As Integer
   

Parameters:

Array_ND : de matrix om te onderzoeken.

Voorbeeld:


      Sub Example_CountDims()
      Dim a(1 To 10, -3 To 12, 5)
          MsgBox SF_Array.CountDims(a) ' 3
      End Sub
   

Difference

Bouwt een set op, als een zero-based matrix , door de verschil-operator te gebruiken op de twee invoer-matrixen. De items in de uitvoer komen uit het eerste invoer-matrix en niet uit het tweede.
Het uitvoer-matrix is oplopend gesorteerd.
Beide invoer-matrixen moeten gelijksoortig gevuld zijn en hun items moeten van hetzelfde type zijn. Lege en Null items zijn niet toegestaan.
Bij het vergelijken van tekst is er een keuze tussen wel/niet hoofdlettergevoelig.

Syntaxis:


      SF_Array.Difference(Array1_1D As Variant, Array2_1D As Variant[, CaseSensitive As Boolean]) As Variant
   

Parameters:

Array1_1D : Een eendimensionale matrix waarvan de items bekeken worden voor verwijdering.

Array2_1D : Een eendimensionale matrix waarvan de items worden afgetrokken van de eerste invoer-matrix.

CaseSensitive : Alleen als de matrices teksten bevatten, standaardwaarde is False.

Voorbeeld:


      Sub Example_Difference()
      Dim a As Variant
          a = SF_Array.Difference(Array("A", "C", "A", "b", "B"), Array("C", "Z", "b"), True)
              ' ("A", "B")
      End Sub
   

ExportToTextFile

Schrijf alle items van de matrix naar een tekstbestand. Als het bestand al bestaat dan wordt het bestand, zonder waarschuwing, overschreven.

Syntaxis:


      SF_Array.ExportToTextFile(Array_1D As Variant, FileName As String, [Encoding As String]) As Boolean
   

Parameters:

Array_1D : de te exporteren matrix. Deze moet alleen teksten bevatten.

BestandsNaam : de bestandsnaam van het tekstbestand dat de gegevens bevat. De naam wordt bepaald door de huidige FileNaming-eigenschap van de SF_FileSystem-service. Standaardwaarde is = any (zowel het URL-formaat als het formaat van het gebruikte operating systeem zijn toegestaan).

Encoding : De te gebruiken tekenset. Gebruik een van de namen die in lijst IANA tekenset staat. Controleer wel of deze tekenset door LibreOffice is geïmplementeerd. Standaard is "UTF-8".

Voorbeeld:


      Sub Example_ExportToTextFile()
          SF_Array.ExportToTextFile(Array("A","B","C","D"), "C:\Temp\A short file.txt")
      End Sub
   

ExtractColumn

Haal uit een tweedimensionale matrix een bepaalde kolom als een nieuwe matrix.
De LBound-ondergrens en de UBound-bovengrens zijn gelijk aan die van de eerste dimensie van het invoer-matrix.

Syntaxis:


      SF_Array.ExtractColumn(Array_2D As Variant, ColumnIndex As Long) As Variant
   

Parameters:

Array_2D : De matrix waar gegevens uitgehaald moeten worden.

ColumnIndex : Het nummer van de kolom die eruit gehaald moet worden, dit moet tussen de grenzen [LBound, UBound] liggen.

Voorbeeld:


      Sub Example_ExtractColumn
         'Maakt een 3x3 matrix: |1, 2, 3|
         '                      |4, 5, 6|
         '                      |7, 8, 9|
         Dim mat as Variant, col as Variant
         mat = SF_Array.AppendRow(Array(), Array(1, 2, 3))
         mat = SF_Array.AppendRow(mat, Array(4, 5, 6))
         mat = SF_Array.AppendRow(mat, Array(7, 8, 9))
         'Haalt de derde kolom op: |3, 6, 9|
         col = SF_Array.ExtractColumn(mat, 2)
      End Sub
   

ExtractRow

Haal uit een tweedimensionale matrix een bepaalde rij als een nieuwe matrix.
De LBound-ondergrens en de UBound-bovengrens zijn gelijk aan die van de eerste dimensie van het invoer-matrix.

Syntaxis:


      SF_Array.ExtractRow(Array_2D As Variant, RowIndex As Long) As Variant
   

Parameters:

Array_2D : De matrix waar gegevens uitgehaald worden.

RowIndex : het rijnummer dat opgehaald moet worden, moet tussen de grenzen [LBound, UBound] liggen.

Voorbeeld:


      Sub Example_ExtractRow
         'Maakt een 3x3 matrix: |1, 2, 3|
         '                      |4, 5, 6|
         '                      |7, 8, 9|
         Dim mat as Variant, row as Variant
         mat = SF_Array.AppendRow(Array(), Array(1, 2, 3))
         mat = SF_Array.AppendRow(mat, Array(4, 5, 6))
         mat = SF_Array.AppendRow(mat, Array(7, 8, 9))
         'Haalt de eerste rij op: |1, 2, 3|
         row = SF_Array.ExtractRow(mat, 0)
      End Sub
   

Flatten

Plaats alle enkele items van een matrix en alle items in een submatrix in een nieuwe matrix zonder submatrixen. Lege submatrixen worden overgeslagen en submatrixen met meer dan een dimensie worden niet afgevlakt.

Syntaxis:


      SF_Array.Flatten(Array_1D As Variant) As Variant
   

Parameters:

Array_1D : de al bestaande matrix, deze matrix kan leeg zijn.

Voorbeeld:


      Sub Example_Flatten()
      Dim a As Variant
          a = SF_Array.Flatten(Array(Array(1, 2, 3), 4, 5))
              ' (1, 2, 3, 4, 5)
      End Sub
   
tip

U kunt de methode Flatten gebruiken met andere methoden als Append en Prepend om een aantal eendimensionale matrixen samen te voegen tot een eendimensionaal matrix.


Voorbeeld:

Nu een voorbeeld hoe de methoden Flatten en Append samen gebruikt kunnen worden om drie matrixen samen te voegen.


      Sub Concatenate_Example
         'Maakt drie matrixen aan voor dit voorbeeld
         Dim a as Variant, b as Variant, c as Variant
         a = Array(1, 2, 3)
         b = Array(4, 5)
         c = Array(6, 7, 8, 9)
         'Voegt drie matrixen samen tot een eendimensionale matrix
         Dim arr as Variant
         arr = SF_Array.Flatten(SF_Array.Append(a, b, c))
         '(1, 2, 3, 4, 5, 6, 7, 8, 9)
      End Sub
   

ImportFromCSVFile

Importeer de gegevens in een bestand met komma gescheiden waarden (CSV-bestand). Er kan een ander teken als scheidingsteken worden gebruikt.

De van toepassing zijnde CSV-indeling is beschreven in IETF Common Format and MIME Type for CSV Files.

Elke regel in het bestand bevat een volledig record (splitsen van regels is niet toegestaan).
Reeksen als \n, \t, ... worden echter niet gewijzigd. Gebruik de methode SF_String.Unescape() om hiermee om te gaan.

De methode retourneert een tweedimensionaal array waar de rijen overeenkomen met één regel in het invoerbestand, de kolommen komen overeen met een veld in de regel. De velden worden niet op type gecontroleerd. Er wordt geprobeerd de numerieke velden en de datumvelden te bepalen.

Als een regel meer of minder velden bevat dan de eerste regel wordt er een exception gemaakt. Lege regels worden overgeslagen. Als het aantal invoerregels hoger is dan de limiet (bekijk de code), wordt er een waarschuwing gemaakt en wordt de uitvoer beperkt tot de limiet.

Syntaxis:


      SF_Array.ImportFromCSVFile(FileName As String, [Delimiter As String], [DateFormat As String]) As Variant
   

Parameters:

FileName : de naam van het tekstbestand met de gegevens. De naam wordt bepaald door de huidige eigenschap FileNaming van de service SF_FileSystem. Standaard is 'any' (zowel URL-formaat als het formaat van het besturingssysteem zijn toegestaan).

Scheidingsteken : Een enkel teken, meestal een komma, puntkomma of een TAB teken. Standaardwaarde is een ",".

Datumopmaak : Een speciaal mechanisme behandelt de datums als de Datumopmaak "YYYY-MM-DD", "DD-MM-YYYY" of "MM-DD-YYYY" is. Het streepje (-) kan ook een punt (.), slash (/) of een spatie zijn. Andere opmaak wordt genegeerd. Datumingaves, die standaard "" zijn, wordt gezien als tekst.

Voorbeeld:

Gegeven dit CSV bestand:


      Name,DateOfBirth,Address,City
      Anna,2002/03/31,"Rue de l'église, 21",Toulouse
      Fred,1998/05/04,"Rue Albert Einstein, 113A",Carcassonne
   

      Sub Example_ImportFromCSVFile()
      Dim a As Variant
          a = SF_Array.ImportFromCSVFile("C:\Temp\myFile.csv", DateFormat := "YYYY/MM/DD")
          MsgBox a(0, 3)    ' City
          MsgBox TypeName(a(1, 2))    ' Date
          MsgBox a(2, 2)    ' Rue Albert Einstein, 113A
      End Sub
   

IndexOf

Zoek in een eendimensionaal array naam een getal, een tekst of een datum. Tekstvergelijking kan hoofdlettergevoelig zijn.
Als het array gesorteerd is, dan moet dat homogeen gevuld zijn, waarmee wordt bedoelt dat alle items van hetzelfde type moeten zijn (de waarden Empty en Null zijn niet toegestaan).
Als het array niet gesorteerd is maar wel is aangegeven dat dat zo is, dan is het resultaat niet voorspelbaar.
Bij gesorteerde arrays wordt binair gezocht. Bij niet gesorteerde arrays wordt het hele array doorzocht waarbij de waarden Empty en Null worden overgeslagen.

Het resultaat van de methode is LBound(array) - 1 als er niets wordt gevonden.

Syntaxis:


      SF_Array.IndexOf(Array_1D, ToFind As Variant, [CaseSensitive As Boolean], [SortOrder As String]) As Long
   

Parameters:

Array_1D : de te doorzoeken matrix.

ZoekNaar : het getal, de datum of de tekst waarnaar gezocht moet worden.

Hoofdlettergevoelig : Alleen voor het vergelijken van teksten, standaardwaarde is False.

SortOrder : "ASC", "DESC" or "" (= not sorted, default)

Voorbeeld:


      Sub Example_IndexOf()
          MsgBox SF_Array.IndexOf(Array("A","B","c","D"), "C", SortOrder := "ASC") ' 2
          MsgBox SF_Array.IndexOf(Array("A","B","c","D"), "C", CaseSensitive := True) ' -1
      End Sub
   

Insert

Insert before a given index of the input array the items listed as arguments.
Arguments are inserted blindly. Each of them might be either a scalar of any type or a subarray.

Syntaxis:


      SF_Array.Insert(Array_1D As Variant, Before As Long, arg0 As Variant, [arg1 As Variant], ...) As Variant
   

Parameters:

Array_1D : the pre-existing array, may be empty.

Before : the index before which to insert; must be in the interval [LBound, UBound + 1].

arg0, ... : a list of items to insert inside Array_1D.

Voorbeeld:


      Sub Example_Insert()
      Dim a As Variant
          a = SF_Array.Insert(Array(1, 2, 3), 2, "a", "b")
              ' (1, 2, "a", "b", 3)
      End Sub
   

InsertSorted

Insert in a sorted array a new item on its place.
The array must be filled homogeneously, meaning that all items must be scalars of the same type.
Empty and Null items are forbidden.

Syntaxis:


      SF_Array.InsertSorted(Array_1D As Variant, Item As Variant, SortOrder As String, CaseSensitive As Boolean) As Variant
   

Parameters:

Array_1D : The array to sort.

Item : The scalar value to insert, of the same type as the existing array items.

SortOrder : "ASC" (default) or "DESC".

Hoofdlettergevoelig : Alleen voor het vergelijken van teksten, standaardwaarde is False.

Voorbeeld:


      Sub Example_InsertSorted()
      Dim a As Variant
          a = SF_Array.InsertSorted(Array("A", "C", "a", "b"), "B", CaseSensitive := True)
              ' ("A", "B", "C", "a", "b")
      End Sub
   

Intersection

Build a set, as a zero-based array, by applying the intersection set operator on the two input arrays. Resulting items are contained in both arrays.
The resulting array is sorted in ascending order.
Both input arrays must be filled homogeneously, in other words all items must be scalars of the same type. Empty and Null items are forbidden.
Text comparison can be case sensitive or not.

Syntaxis:


      SF_Array.Intersection(Array1_1D As Variant, Array2_1D As Variant[, CaseSensitive As Boolean]) As Variant
   

Parameters:

Array1_1D : The first input array.

Array2_1D : The second input array.

Hoofdlettergevoelig : Voor matrices die teksten bevatten, standaardwaarde is False.

Voorbeeld:


      Sub Example_Intersection()
      Dim a As Variant
          a = SF_Array.Intersection(Array("A", "C", "A", "b", "B"), Array("C", "Z", "b"), True)
              ' ("C", "b")
      End Sub
   

Join2D

Join a two-dimensional array with two delimiters, one for the columns, one for the rows.

Syntaxis:


      SF_Array.Join2D(Array_2D As Variant, ColumnDelimiter As String, RowDelimiter As String, Quote As Boolean) As String
   

Parameters:

Array_2D : Each item must be either text, a number, a date or a boolean.
Dates are transformed into the YYYY-MM-DD hh:mm:ss format.
Invalid items are replaced by a zero-length string.

ColumnDelimiter : Delimits each column (default = Tab/Chr(9)).

RowDelimiter: delimits each row (default = LineFeed/Chr(10))

Quote : if True, protect strings with double quotes. The default is False.

Voorbeeld:


      Sub Example_Join2D()
      -                     | 1, 2, "A", [2020-02-29], 5      |
      -    SF_Array.Join_2D(| 6, 7, "this is a string", 9, 10 |, ",", "/")
      -            ' "1,2,A,2020-02-29 00:00:00,5/6,7,this is a string,9,10"
      End Sub
   

Prepend

Prepend at the beginning of the input array the items listed as arguments.

Syntaxis:


      SF_Array.Prepend(Array_1D As Variant, arg0 As Variant, [arg1 As Variant], ...) As Variant
   

Parameters:

Array_1D : the pre-existing array, may be empty.

arg0, ... : a list of items to prepend to Array_1D.

Voorbeeld:


      Sub Example_Prepend()
      Dim a As Variant
          a = SF_Array.Prepend(Array(1, 2, 3), 4, 5)
              ' (4, 5, 1, 2, 3)
      End Sub
   

PrependColumn

Prepend to the left side of a two dimension array a new column. The resulting array has the same lower boundaries as the initial two dimension array.

Syntaxis:


      SF_Array.PrependColumn(Array_2D As Variant, Column As Variant) As Variant
   

Parameters:

Array_2D : the pre-existing array, may be empty. If that array has 1 dimension, it is considered as the last column of the resulting 2 dimension array.

Column : a 1 dimension array with as many items as there are rows in Array_2D.

Voorbeeld:


      Sub Example_PrependColumn()
      Dim a As Variant, b As variant
          a = SF_Array.PrependColumn(Array(1, 2, 3), Array(4, 5, 6))
              ' ((4, 1), (5, 2), (6, 3))
          b = SF_Array.PrependColumn(Array(), Array(1, 2, 3))
              ' ∀ i ∈ {0 ≤ i ≤ 2} : b(0, i) ≡ i
      End Sub
   

PrependRow

Prepend at the beginning of a two dimension array a new row. The resulting array has the same lower boundaries as the initial two dimension array.

Syntaxis:


      SF_Array.PrependRow(Array_2D As Variant, Row As Variant) As Variant
   

Parameters:

Array_2D : the pre-existing array, may be empty. If that array has 1 dimension, it is considered as the last row of the resulting 2 dimension array.

Row : a 1 dimension array containing as many items as there are rows in Array_2D.

Voorbeeld:


      Sub Example_PrependRow()
      Dim a As Variant, b As variant
          a = SF_Array.PrependRow(Array(1, 2, 3), Array(4, 5, 6))
              ' ((4, 5, 6), (1, 2, 3))
          b = SF_Array.PrependRow(Array(), Array(1, 2, 3))
              ' ∀ i ∈ {0 ≤ i ≤ 2} : b(i, 0) ≡ i
      End Sub
   

RangeInit

Initialize a new zero-based array with numeric values.

Syntaxis:


      SF_Array.RangeInit(From As [number], UpTo As [number] [, ByStep As [number]]) As Variant
   

Parameters:

From : value of the first item.

UpTo : The last item should not exceed UpTo.

ByStep : The difference between two successive items (default = 1).

Voorbeeld:


      Sub Example_RangeInit()
      Dim a As Variant
          a = SF_Array.RangeInit(10, 1, -1)
              ' (10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
      End Sub
   

Reverse

Return the reversed one dimension input array.

Syntaxis:


      SF_Array.Reverse(Array_1D As Variant) As Variant
   

Parameters:

Array_1D : The array to reverse.

Voorbeeld:


      Sub Example_Reverse()
      Dim a As Variant
          a = SF_Array.Reverse(Array("a", 2, 3, 4))
              ' (4, 3, 2, "a")
      End Sub
   

Shuffle

Return a random permutation of a one dimension array.

Syntaxis:


      SF_Array.Shuffle(Array_1D As Variant) As Variant
   

Parameters:

Array_1D : The array to shuffle.

Voorbeeld:


      Sub Example_Shuffle()
      Dim a As Variant
          a = SF_Array.Shuffle(Array(1, 2, 3, 4))
              ' Unpredictable
      End Sub
   

Slice

Return a subset of a one dimension array.

Syntaxis:


      SF_Array.Slice(Array_1D As Variant, From As Long, [UpTo As Long]) As Variant
   

Parameters:

Array_1D : The array to slice.

From : The lower index in Array_1D of the subarray to extract (From included)

UpTo : The upper index in Array_1D of the subarray to extract (UpTo included). Default = upper bound of Array_1D. If UpTo < From then the returned array is empty.

Voorbeeld:


      Sub Example_Slice()
      Dim a As Variant
          a = SF_Array.Slice(Array(1, 2, 3, 4, 5), 1, 3) ' (2, 3, 4)
      End Sub
   

Sort

Sort a one dimension array in ascending or descending order. Text comparisons can be case-sensitive or not.
The array must be filled homogeneously, which means that items must be scalars of the same type.
Empty and Null items are allowed. Conventionally Empty < Null < any other scalar value.

Syntaxis:


      SF_Array.Sort(Array_1D As Variant, SortOrder As String, CaseSensitive As Boolean) As Variant
   

Parameters:

Array_1D : The array to sort.

SortOrder : "ASC" (default) or "DESC".

Hoofdlettergevoelig : Alleen voor het vergelijken van teksten, standaardwaarde is False.

Voorbeeld:


      Sub Example_Sort()
      Dim a As Variant
          a = SF_Array.Sort(Array("a", "A", "b", "B", "C"), CaseSensitive := True)
              ' ("A", "B", "C", "a", "b")
      End Sub
   

SortColumns

Return a permutation of the columns of a two dimension array, sorted on the values of a given row.
The row must be filled homogeneously, which means that all items must be scalars of the same type.
Empty and Null items are allowed. Conventionally Empty < Null < any other scalar value.

Syntaxis:


      SF_Array.SortColumns(Array_1D As Variant, RowIndex As Long, SortOrder As String, CaseSensitive As Boolean) As Variant
   

Parameters:

Array_1D : The array to sort.

RowIndex : The index of the row to sort the columns on.

SortOrder : "ASC" (default) or "DESC".

Hoofdlettergevoelig : Alleen voor het vergelijken van teksten, standaardwaarde is False.

Voorbeeld:


      Sub Example_SortColumns()
      -                         | 5, 7, 3 |            ' | 7, 5, 3 |
      -    SF_Array.SortColumns(| 1, 9, 5 |, 2, "ASC") ' | 9, 1, 5 |
      -                         | 6, 1, 8 |            ' | 1, 6, 8 |
      End Sub
   

SortRows

Return a permutation of the rows of a two dimension array, sorted on the values of a given column.
The column must be filled homogeneously, therefore all items must be scalars of the same type.
Empty and Null items are allowed. Conventionally Empty < Null < any other scalar value.

Syntaxis:


      SF_Array.SortRows(Array_1D As Variant, ColumnIndex As Long, SortOrder As String, CaseSensitive As Boolean) As Variant
   

Parameters:

Array_1D : The array to sort.

RowIndex : The index of the column to sort the rows on.

SortOrder : "ASC" (default) or "DESC".

Hoofdlettergevoelig : Alleen voor het vergelijken van teksten, standaardwaarde is False.

Voorbeeld:


      Sub Example_SortRows()
      -                      | 5, 7, 3 |            ' | 1, 9, 5 |
      -    SF_Array.SortRows(| 1, 9, 5 |, 2, "ASC") ' | 5, 7, 3 |
      -                      | 6, 1, 8 |            ' | 6, 1, 8 |
      End Sub
   

Transpose

Swap rows and columns in a two dimension array.

Syntaxis:


      SF_Array.Transpose(Array_2D As Variant) As Variant
   

Parameters:

Array_2D : The array to transpose.

Voorbeeld:


      Sub Example_Transpose()
      -                       | 1, 2 |  ' | 1, 3, 5 |
      -    SF_Array.Transpose(| 3, 4 |) ' | 2, 4, 6 |
      -                       | 5, 6 |
      End Sub
   

TrimArray

Remove from a one dimension array all Null, Empty and zero-length entries.
String items are trimmed with LibreOffice Basic Trim() function.

Syntaxis:


      SF_Array.TrimArray(Array_1D As Variant) As Variant
   

Parameters:

Array_1D : de te doorzoeken matrix.

Voorbeeld:


      Sub Example_TrimArray()
      Dim a As Variant
          a = SF_Array.TrimArray(Array("A","B",Null," D "))
              ' ("A","B","D")
      End Sub
   

Union

Build a set, as a zero-based array, by applying the union operator on the two input arrays. Resulting items originate from both arrays.
The resulting array is sorted in ascending order.
Both input arrays must be filled homogeneously, their items must be scalars of the same type. Empty and Null items are forbidden.
Text comparison can be case sensitive or not.

Syntaxis:


      SF_Array.Union(Array1_1D As Variant, Array2_1D As Variant[, CaseSensitive As Boolean]) As Variant
   

Parameters:

Array1_1D : The first input array.

Array2_1D : The second input array.

Hoofdlettergevoelig : Alleen als de matrices teksten bevatten, standaardwaarde is False.

Voorbeeld:


      Sub Example_Union()
      Dim a As Variant
          a = SF_Array.Union(Array("A", "C", "A", "b", "B"), Array("C", "Z", "b"), True)
              ' ("A", "B", "C", "Z", "b")
      End Sub
   

Unique

Build a set of unique values derived from the input array.
The input array must be filled homogeneously, its items must be scalars of the same type. Empty and Null items are forbidden.
Text comparison can be case sensitive or not.

Syntaxis:


      SF_Array.Unique(Array_1D As Variant, CaseSensitive As Boolean]) As Variant
   

Parameters:

Array_1D : The input array.

Hoofdlettergevoelig : Alleen als de matrix teksten bevat, standaardwaarde is False.

Voorbeeld:


      Sub Example_Unique()
      Dim a As Variant
          a = SF_Array.Unique(Array("A", "C", "A", "b", "B"), CaseSensitive := True)
              '  ("A", "B", "C", "b")
      End Sub
   
warning

All ScriptForge Basic routines or identifiers that are prefixed with an underscore character "_" are reserved for internal use. They are not meant be used in Basic macros.