|
-
Jan 28th, 2004, 10:58 AM
#1
Thread Starter
Addicted Member
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
-
Jan 28th, 2004, 12:13 PM
#2
yay gay
You can't. In VB.NET all kinds of arrays are 0-indexed which means they all start by zero.
\m/  \m/
-
Jan 28th, 2004, 12:22 PM
#3
New Member
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.
-
Feb 2nd, 2004, 01:36 PM
#4
Lively Member
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.
-
Feb 2nd, 2004, 07:02 PM
#5
PowerPoster
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.
-
Sep 16th, 2005, 10:19 AM
#6
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:
Dim arrObj As Array = Array.CreateInstance(GetType(Integer), lengths, lBounds)
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:
Dim MyI As Integer
Dim lengths() As Integer = {5}
Dim lBounds() As Integer = {-3}
Dim arrObj As Array = Array.CreateInstance(GetType(Integer), lengths, lBounds)
'Now, Lets see what we have:
MsgBox(arrObj.GetLowerBound(0) & " to " & arrObj.GetUpperBound(0))
'now, lets see about any assignment issues
For MyI = arrObj.GetLowerBound(0) To arrObj.GetUpperBound(0)
arrObj(MyI) = 2 * MyI
Next
'now, lets see if assignments worked
For MyI = arrObj.GetLowerBound(0) To arrObj.GetUpperBound(0)
MsgBox(arrObj(MyI))
Next

-Lou
-
Sep 16th, 2005, 10:56 AM
#7
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|