Dec 20, 2004 #1 denis60 Technical User Apr 19, 2001 89 CA Hi! Is it possible to add 2 array of the same width like: arr3 = arr1 + arr2
Dec 20, 2004 #2 getdani Programmer Nov 24, 2004 8 ET if u want the L value aray to have the size of sum of the two args ex ar1=(2,2,1) ar2=(1,4) 'expected otput ar3(2,2,1,1,4) if so do this dim ar3() as integer ' dynamic array dim lar1 dim lar2 .... lar1=ubound(ar1) lar2=ubound(ar2) redim ra3(lar1+lar2) as integer 'use a loop to copy the value Upvote 0 Downvote
if u want the L value aray to have the size of sum of the two args ex ar1=(2,2,1) ar2=(1,4) 'expected otput ar3(2,2,1,1,4) if so do this dim ar3() as integer ' dynamic array dim lar1 dim lar2 .... lar1=ubound(ar1) lar2=ubound(ar2) redim ra3(lar1+lar2) as integer 'use a loop to copy the value
Dec 20, 2004 Thread starter #3 denis60 Technical User Apr 19, 2001 89 CA Ok, i don't have choice, i have to use a "for loop" statement to do that. Nothing faster like a strait liner command Upvote 0 Downvote
Ok, i don't have choice, i have to use a "for loop" statement to do that. Nothing faster like a strait liner command
Dec 20, 2004 #4 AEtherson Programmer Oct 10, 2003 119 GB use this to do a fast copy Private Declare Sub CopyMemory Lib "kernel32" Alias _ "RtlMoveMemory" (Destination As Any, Source As Any, _ ByVal Length As Long) Public Sub MemAppend(mDest() As Byte, Source1() As Byte, source2() As Byte) Dim i As Integer CopyMemory mDest(0), Source1(0), 2 CopyMemory mDest(2), source2(0), 2 For i = 0 To UBound(mDest) Debug.Print mDest(i) Next End Sub Public Sub test() Dim a(1) As Byte Dim b(1) As Byte Dim c(3) As Byte a(0) = 1 a(1) = 2 b(0) = 3 b(1) = 4 MemAppend c, a, b End Sub Upvote 0 Downvote
use this to do a fast copy Private Declare Sub CopyMemory Lib "kernel32" Alias _ "RtlMoveMemory" (Destination As Any, Source As Any, _ ByVal Length As Long) Public Sub MemAppend(mDest() As Byte, Source1() As Byte, source2() As Byte) Dim i As Integer CopyMemory mDest(0), Source1(0), 2 CopyMemory mDest(2), source2(0), 2 For i = 0 To UBound(mDest) Debug.Print mDest(i) Next End Sub Public Sub test() Dim a(1) As Byte Dim b(1) As Byte Dim c(3) As Byte a(0) = 1 a(1) = 2 b(0) = 3 b(1) = 4 MemAppend c, a, b End Sub
Dec 20, 2004 #5 chiph Programmer Jun 9, 1999 9,878 US What sort of add are you looking to do? Are you trying to make a new array, only longer (append array B to array A)? Or are you trying to add each element in the first array to the corresponding element in the second array? Chip H. ____________________________________________________________________ If you want to get the best response to a question, please read FAQ222-2244 first Upvote 0 Downvote
What sort of add are you looking to do? Are you trying to make a new array, only longer (append array B to array A)? Or are you trying to add each element in the first array to the corresponding element in the second array? Chip H. ____________________________________________________________________ If you want to get the best response to a question, please read FAQ222-2244 first