Results 1 to 6 of 6

Thread: Setting a new length for an array without having to redim it....

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Guess....i have wooden shoes, in my free time i sell tulips and I live in a huge windmill...
    Posts
    176

    Setting a new length for an array without having to redim it....

    How?
    JpEgy

  2. #2
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    can't
    Please rate my post.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Guess....i have wooden shoes, in my free time i sell tulips and I live in a huge windmill...
    Posts
    176
    So making a new array, loading stuff into there and then move it to the first array is the only way?
    JpEgy

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    hmm what about Redim preserve?
    this will keep the contents of the array while changing it's size.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  5. #5
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    You dont have to do that. If you need a dynamic array, look in the collection class.

    Look up ArrayList. Its perfect for what you want to do. The object that you want to declare as an array, you dont have to do that.

    Here is an example

    'Structure
    VB Code:
    1. Structure SCD
    2.         Public cdTitle As String
    3.         Public cdGenre As String
    4.         Public cdIsbn As Long
    5.         Public cdTracks As Integer
    6.         Public cdArtist As String
    7. End Structure

    'declaring an arraylist
    VB Code:
    1. Public cdArray As New ArrayList()

    'declaring a new cd from the structure SCD
    VB Code:
    1. Public newCD As SCD

    VB Code:
    1. Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
    2. 'each time button is clicked the structure is filed from the text boxes, then the newCD is added to the cdArray arraylist
    3.  
    4. With newCD
    5.             .cdTitle = cdTitle.Text
    6.             .cdGenre = cdGenre.Text
    7.             .cdIsbn = cdIsbn.Text
    8.             .cdArtist = cdArtist.Text
    9.             .cdTracks = cdTracks.Text
    10. End With
    11.  
    12. ccdArray.Add(newCD)      
    13.  
    14. End Sub

    Hoped that helped. Look up ArrayList and you should find some usefull information
    Dont gain the world and lose your soul

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Guess....i have wooden shoes, in my free time i sell tulips and I live in a huge windmill...
    Posts
    176
    Thnx, i already did the first part but i didn't relize i could do it this way
    Last edited by JpEgy; Mar 31st, 2002 at 07:05 PM.
    JpEgy

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