i have 2 arrray.
array2 have 10 elements
array 1 have 5 elements

i want to copy all the element of array1 to array2 to fill all the 10spaces..ie arra2 is filled 2times of array1 how it done.

array1={1,2,3,4,5}
now array2 is filled like(1,2,3,4,5,1,2,3,4,5}

need urgently plz help..

Recommended Answers

All 5 Replies

That is one way of doing it not knowing what you want to achieve:

    Dim array1(5) As Integer
    Dim array2(10) As Integer 'array2 is filled like(1,2,3,4,5,1,2,3,4,5}

Private Sub Form_Load()

    Dim i, j As Integer
    For i = 1 To 5
        array1(i) = i
    Next i
    For j = 1 To 5
        array2(j) = j
    Next j
End Sub

Private Sub Command1_Click()
    Dim k, l As Integer
    l = 0
    For k = 6 To 10
        l = l + 1
        array2(k) = array1(l)
    Next k
    For i = 1 To 10
        Debug.Print (array2(i))
    Next i
End Sub

Or

For i = 0 to 4
    array1(i) = i + 1
    array2(i) = i + 1
    array2(i+5) = i + 1
Next
For i = 0 to 4
    array1(i) = i + 1
    array2(i) = i + 1
    array2(i+5) = i + 1
Next

what is mean ...

If you have two arrays

Dim array1(5) As Integer
Dim array2(10) As Integer

then after the loop executes they will have the values

array1 = {1, 2, 3, 4, 5}
array2 = {1, 2, 3, 4, 5, 1, 2, 3, 4, 5}

which is what you said you wanted.

To copy from array1 to array 2 do

For i = 0 To 4
    array2(i) = array1(i)
    array2(i+5) = array1(i)
Next
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.