How can I pass the data of an Array to another Array using VB6?
            Asked
            
        
        
            Active
            
        
            Viewed 1.0k times
        
    0
            
            
         
    
    
        Mark Bertenshaw
        
- 5,594
- 2
- 27
- 40
 
    
    
        user3391894
        
- 9
- 1
- 1
- 16
- 
                    You want to copy the array? – Blorgbeard Apr 07 '14 at 04:23
- 
                    yes, because I have a computation in my program I should retain the data of current time that's why I needed it. `Array2 - Array1` then after the computation I will pass the data of `Array2` to `Array1` so that the `Array1` must have already a value and the `Array2` must be empty – user3391894 Apr 07 '14 at 04:28
3 Answers
5
            
            
        In VB6, array is copied on a simple assignment.
Dim arr1() As Long
Dim arr2() As Long
ReDim arr1(1 To 10)
'Fill arr1 with data
arr2 = arr1
 
    
    
        GSerg
        
- 76,472
- 17
- 159
- 346
- 
                    
- 
                    +1 Just for fun: you can also use API calls but its much much harder http://www.xbeat.net/vbspeed/c_SliceLng.htm – MarkJ Apr 07 '14 at 18:52
- 
                    @MarkJ When it comes to fun, it is more fun to create [linked subarrays](http://stackoverflow.com/q/11713408/11683) ;) – GSerg Apr 07 '14 at 19:56
0
            
            
        Try this:
        Dim lArray1(3) As Long
        Dim lArray2(3) As Long
        Dim count As Long
        lArray1(0) = 1
        lArray1(1) = 2
        lArray1(2) = 3
        lArray2(0) = 10
        lArray2(1) = 20
        lArray2(2) = 30
        For count = LBound(lArray1) To UBound(lArray1)
            lArray2(count) = lArray1(count)
        Next count
        Erase lArray2
if its not fixed length you will need to use redim in the loop.
0
            
            
        I have already answered my questions :) Thank you guys for the help but this is what I did.
'Delete items in Array first
            For lngIndex = 0 To UBound(time2) - 1
                time2(lngIndex) = time2(lngIndex + 1)
            Next
'Next thing is
'Insert items in Array
            For lngIndex = UBound(time1) - 1 To 0 Step -1
                time1(lngIndex + 1) = time2(lngIndex)
            Next
This code solve my problem :)
 
    
    
        user3391894
        
- 9
- 1
- 1
- 16