Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long) 'Gruppo di Sub per eseguire la copia di 'un certo numero di elementi da un array 'ad un altro usando la API CopyMemory: i due 'array DEVONO essere dello stesso tipo e NON 'POSSONO ESSERE di tipo: 'String a lunghezza variabile 'Variant 'Oggetti 'Type contenenti stringhe a lunghezza variabile Public Sub CopyArrayINT( _ ArraySource() As Integer, _ ArrayDest() As Integer, _ Optional ByVal iStart As Integer, _ Optional ByVal iEnd As Integer, _ Optional ByVal iInsertAt As Integer) Dim iNElements As Integer Dim iIndiceD As Integer Dim iIndiceS As Integer 'Controlla il valore del primo indice 'dell'array sorgente iIndiceS = LBound(ArraySource) If iStart > iIndiceS Then iIndiceS = iStart iIndiceD = LBound(ArrayDest) 'Controlla se e' stata specificata un 'elemento diverso dal primo dove 'inserire gli elementi da copiare If iInsertAt > iIndiceD Then _ iIndiceD = iInsertAt 'Numero di elementi da copiare (max quelli 'contenuti nell'array di destinazione o 'quelli contenuti nell'array sorgente) If iEnd = 0 Then iNElements = UBound(ArraySource) - _ iIndiceS + 1 End If Dim iMaxEl As Integer iMaxEl = UBound(ArrayDest) - iIndiceD + 1 If iNElements > iMaxEl Then iNElements = iMaxEl End If If iNElements = 0 Then iNElements = iEnd - iIndiceS + 1 End If CopyMemory ArrayDest(iIndiceD), _ ArraySource(iIndiceS), _ Len(ArrayDest(iIndiceD)) * _ iNElements End Sub Possiamo usare la funzione API CopyMemory per copiare un intero array (o anche un gruppo di elementi contigui) su un altro array dello stesso tipo. Ecco una funzione che esegue la copia di un array Integer, ma che puo' essere copiata e modificata per copiare array di tutti i tipi eccetto Variant, String a lunghezza variabile ed oggetti. |