Results 1 to 4 of 4

Thread: [RESOLVED] declaring an array of unfixed size (newby :) )

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    42

    Resolved [RESOLVED] declaring an array of unfixed size (newby :) )

    Hi all.

    should be an easy one hopefully

    i just want to declare a (id call it dynamic, grows and shrinks according to its contents) array

    Dim data_file() As String

    but then how do i deal with this array?
    assign elements to it etc
    you dont seem to be able to handle it like a

    Code:
    Dim data_file(10000) As String
    array.

    cheers

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: declaring an array of unfixed size (newby :) )

    If you want to be able to remove and add elements from the array you should consider using a Collection or List instead.
    You shouldnt be declaring a larger array than needed, for example if I want to fill a process array with the processes on the computer I could in theory do this:

    VB Code:
    1. Dim p(1000) as Process
    2. p = Process.GetProcesses()
    But that would be totally unnecessary. If you dont assign any upper bound value to the array it will resize itself to the needed size:

    VB Code:
    1. Dim p() as Process
    2. p = Process.GetProcesses()

    But like I said it looks to me like you should be using a collection or list instead.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: declaring an array of unfixed size (newby :) )

    Collections are the best solution.

    Code:
    dim data_file as arrayList = new ArrayList()
    and then play with the properties and methods of the class

  4. #4

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    42

    Re: declaring an array of unfixed size (newby :) )

    okay guys, thanks for that

    il start taking a little look into that.

    cheers for the prompt response

    Andy

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