Variable based array size


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Variable based array size

  1. #1
    Nikhil Guest

    Variable based array size


    Please any one tell me how to create array which has the size that is based
    on a value of a variable.

    cODe:

    Dim x
    x=4
    Dim myArr(x)

    Does not work and asks for literal variable in the array size specification.

















  2. #2
    Adrian Forbes Guest

    Re: Variable based array size

    dim myArr()

    ReDIm myArr(x)

    --
    "Don't try to be like Jackie. There is only one Jackie...Study computers
    instead."
    - Jackie Chan

    http://www.aspfaq.com/
    http://www.aspfree.com/authors/adrian/




  3. #3
    Vince Guest

    Re: Variable based array size


    Hi Nikhil,

    You can try the instruction ReDim instead of Dim. (use Dim first to declare
    the array)
    ReDim works with variables or constants.
    if you have already data in the array, use the keyword Preserve:
    Redim Preserve MyArray (VariableDim)



    "Nikhil" <nikhil_kulkarni@dacafe.com> wrote:
    >
    >Please any one tell me how to create array which has the size that is based
    >on a value of a variable.
    >
    >cODe:
    >
    >Dim x
    >x=4
    >Dim myArr(x)
    >
    >Does not work and asks for literal variable in the array size specification.
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center