Results 1 to 7 of 7

Thread: array (x to y) how??

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Location
    Porto Alegre, RS
    Posts
    210

    array (x to y) how??

    in vb6 i can do this:

    dim i(1 to 100) as integer

    how can i do this in vb.net?




    Thank you,

    Guilherme Costa

  2. #2
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    You can't. In VB.NET all kinds of arrays are 0-indexed which means they all start by zero.
    \m/\m/

  3. #3
    New Member
    Join Date
    Jan 2004
    Location
    U.S.A.
    Posts
    4
    You can't.
    1) In VB.Net the lower bound of every array is 0.
    2) Also, when you declare an array in vb6 as you do in your example, you're creating a fixed size array. VB.Net does not have fixed size arrays, you can indicate only the upper bound of the array. So your declaration in VB.Net would be: Dim i(99) as integer.
    Priore

  4. #4
    Lively Member
    Join Date
    Sep 2002
    Posts
    90
    one thing you might try is use an ArrayList

    This will increment the max of the arraylist count by 1 each time you add something into the arraylist. You can also find out how many items are in the arraylist at the end by using the count property.

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Try this for creating a two dimensional array with lower bounds of 1 and -10, with 5 and 21 elements respectively.



    Dim lengths() As Integer = {5, 21}
    Dim lBounds() As Integer = {1, -10}
    Dim arrObj As Array = Array.CreateInstance(GetType(Integer), lengths, lBounds)
    Dim arr1(,) As Integer = CType(arrObj, Integer(,))


    I'm afraid it is a little more complicated for a single dimension array! (Well, I have not worked that one out yet!!!)
    Last edited by taxes; Feb 4th, 2004 at 05:56 AM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  6. #6
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397

    Re: array (x to y) how??

    Hi Taxes!

    I've got a question, and a possible solution for 1-D arrays.

    in your lines:
    VB Code:
    1. Dim arrObj As Array = Array.CreateInstance(GetType(Integer), lengths, lBounds)
    2.         Dim arr1(,) As Integer = CType(arrObj, Integer(,))

    Is there any significant difference between arr1 and arrObj?

    If Not, then the following shows how to make 1 d arrays with an offset lowbound:

    VB Code:
    1. Dim MyI As Integer
    2.         Dim lengths() As Integer = {5}
    3.         Dim lBounds() As Integer = {-3}
    4.         Dim arrObj As Array = Array.CreateInstance(GetType(Integer), lengths, lBounds)
    5.  
    6.         'Now, Lets see what we have:
    7.         MsgBox(arrObj.GetLowerBound(0) & " to " & arrObj.GetUpperBound(0))
    8.  
    9.         'now, lets see about any assignment issues
    10.         For MyI = arrObj.GetLowerBound(0) To arrObj.GetUpperBound(0)
    11.             arrObj(MyI) = 2 * MyI
    12.         Next
    13.  
    14.         'now, lets see if assignments worked
    15.         For MyI = arrObj.GetLowerBound(0) To arrObj.GetUpperBound(0)
    16.             MsgBox(arrObj(MyI))
    17.         Next


    -Lou

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: array (x to y) how??

    Hi lou,

    Looks like that solves the problem for 1 dimensional arrays. You can access them as normal doing it that way.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

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