Results 1 to 5 of 5

Thread: Copy an array *SOLVED*

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833

    Copy an array *SOLVED*

    is there is easier way to copy array values?

    dim Arry() as string

    redim arry(3)

    arry(1)="Jim"
    arry(2)="Bob"
    arry(3)="Harry"

    Dim NewArry() as string

    redim newarry(ubound(arry))

    for a= 0 to ubound(newarry)
    newarry(a)=arry(a)
    next a
    Last edited by kurtsimons; Nov 11th, 2002 at 06:22 PM.
    Kurt Simons
    [I know I'm a hack but my clients don't!]

  2. #2
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872
    first of all if you create an array like you do
    VB Code:
    1. dim Arry() as string
    2. redim arry(3)
    you create an array of 3 strings: arry(0), arry(1), arry(2) and arry(3)
    if you want to create an arry wit only indexes 1 to 3
    use this redim arry(1 to 3) or do it your way but add on on top of your module:
    VB Code:
    1. option base 1
    to copy an array just try this:
    VB Code:
    1. NewArry = Arry
    it works like a charm:

    So:
    VB Code:
    1. Dim Arry() As String
    2.  
    3. ReDim Arry(3)
    4.  
    5. Arry(1) = "Jim"
    6. Arry(2) = "Bob"
    7. Arry(3) = "Harry"
    8.  
    9. Dim NewArry() As String
    10. ReDim NewArry(UBound(Arry))
    11.  
    12. NewArry = Arry
    - Use the thread tools to Mark your Thread as Resolved when your question is answered.
    - Please Rate my answers if they where helpful.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833
    should I delete this before anyone sees it?

    thanks

    - Kurt
    Kurt Simons
    [I know I'm a hack but my clients don't!]

  4. #4
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    Originally posted by kurtsimons
    should I delete this before anyone sees it?
    No. Leave it here, but edit your first post and change the title to include the word "*Solved*"

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833
    I figured out why it didn't work when I first tried this... I didn't redim the array.
    Kurt Simons
    [I know I'm a hack but my clients don't!]

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