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
Printable View
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
You can't. In VB.NET all kinds of arrays are 0-indexed which means they all start by zero.
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.
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.
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!!!)
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
Hi lou,
Looks like that solves the problem for 1 dimensional arrays. You can access them as normal doing it that way.