Results 1 to 6 of 6

Thread: Copy from array1() to array2()? no loop? [solved]

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    20

    Resolved Copy from array1() to array2()? no loop? [solved]

    Hello,

    I have an array with 394 byte elements (array1(393)), what would be the fastest method to copy from element 4 to element 390 to another array? Can this be done without loop?

    Thank you in advance
    Last edited by runtime; Dec 2nd, 2004 at 05:10 PM.

  2. #2
    Hyperactive Member Disiance's Avatar
    Join Date
    Sep 2004
    Location
    Denver, CO
    Posts
    439
    array2(390) = array1(4)
    "I don't want to live alone until I'm married" - M.M.R.P

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    20

    extract from element 4 to element 390

    array2(390) = array1(4) will copy one element, what I need is array2 to contain from element 4 to element 390 of array1...

    Thank you

  4. #4
    Hyperactive Member Disiance's Avatar
    Join Date
    Sep 2004
    Location
    Denver, CO
    Posts
    439
    ohh, ok, sorry for the misinterpretation.
    A loop would be the fastest way to do this.
    You could do this without a loop but that would take 386 lines of code.
    VB Code:
    1. Dim i
    2. For i = 4 to 390
    3.     array2(i-4) = array1(i)
    4. Next i
    "I don't want to live alone until I'm married" - M.M.R.P

  5. #5
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Something like this...
    VB Code:
    1. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, _
    2.                                                                      Source As Any, _
    3.                                                                      ByVal Length As Long)
    4.  
    5. Private Sub Command1_Click()
    6. Dim arr1(0 To 394) As Long
    7. Dim arr2(0 To 389) As Long
    8. Dim x As Long
    9.  
    10.     For x = LBound(arr1) To UBound(arr1)
    11.         arr1(x) = x
    12.     Next
    13.    
    14. [b]    Call CopyMemory(ByVal VarPtr(arr2(0)), ByVal VarPtr(arr1(0)) + (4 * LenB(arr1(0))), (389 - 4) * LenB(arr1(0)))[/b]
    15.  
    16.     For x = LBound(arr2) To UBound(arr2)
    17.         Debug.Print arr2(x)
    18.     Next
    19.  
    20. End Sub
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    20
    Thanx crptcblade CopyMemory works great!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width