Looking for work? Check out our jobs area.

VB.NET

Moderators: seancampbell
Number of threads: 3618
Number of posts: 9200

This Forum Only
Post New Thread

Report
dynamic arrays in vb.net ????? Posted by saraD on 15 Nov 2009 at 7:40 PM
im trying to declare an array with an unknown length and no way of figuring it out untill the actual data has been placed within the array, in c++ it possible to fill a dynamic array with data and then find out the length if u need 2, but in vb.net im not sure, i know abt the redim concept, but does it work in this case...

thank u sooo much !!!
Report
Re: dynamic arrays in vb.net ????? Posted by seancampbell on 16 Nov 2009 at 6:53 AM
You a few options to solve the scenario you are facing.

Firstly, and more directly to your questions, you can declare the size of an array dynamically like this:

'Say I am getting data from the database, and i don't know how
'many rows I am getting...

'At somepoint, I will get a count for the amount of data coming back, and when I get that 'count' i can declare the array like so:

Dim RowCount as Integer = 15

Dim DynamArray(RowCount) As Integer
'Now DynamArray's bounds are 0 - 14

'You can also declare an array with no size:
Dim DynamArray() as Integer

'Then change the length afterwards:
ReDim DynamArray(RowCount)

'And Finally, if you want to add an item to the array:
ReDim Preserve DynamArray(DynamArray.Length)
DynamArray(DynamArray.Length - 1) = Value


Since you understand how to do this enough to have done it in C++, I won't bore you with details... Here is another way to do it, look into using an arrayList, it dynamically holds multiple datatypes

Dim aList As New ArrayList
aList.Add(Object)
aList.Count
aList.Item(0)
Report
Re: dynamic arrays in vb.net ????? Posted by saraD on 16 Nov 2009 at 1:46 PM
thank u for the info, really helped, im still new to vb.net so im kinda learning as i go, thanx again!



 
Popular resources and forums for programmers on Programmersheaven.com
Assembly, Basic, C, C#, C++, Delphi, Java, JavaScript, Pascal, Perl, PHP, Python, Ruby, Visual Basic
© Copyright 2009 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Publisher: Lars Hagelin. Read the latest words from the publisher here.
Be the first to sign up for Lars Hagelin’s In-depth Outsourcing Newsletter here.
bootstrapLabs Logo A bootstrapLabs project.