473,624 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unlimited Array in Visual Basic 8

Joe
hi. simple question: how can one declare Array (or table) with unknown
number of elements, and then assign values to it, example:

Dim TableStrings() as String

TableStrings(0) = "first value"
TableStrings(1) = "second"
TableStrings(2) = "tird" .... etc
?

Feb 25 '07 #1
9 3517
"Joe" <jo*****@tlen.p lschrieb:
hi. simple question: how can one declare Array (or table) with unknown
number of elements, and then assign values to it, example:

Dim TableStrings() as String

TableStrings(0) = "first value"
TableStrings(1) = "second"
TableStrings(2) = "tird" .... etc
You may want to use 'System.Collect ions.Generic.Li st(Of T)'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Feb 26 '07 #2
Joe,

I'm a very fresh beginner to VB.Net, so hopefully I won't screw this up, but
what you need to do is declare the array as you have in your example and add
a counter to loop through each value and assign it to the count value. In
psuedo-code it would look something like...

Declare your counter variable
Declare your array
For Each element in the input data
Assign the values to the array elements (Table(counter) )
'Do other processing if necessary'
Increment the counter by 1 (counter += 1)
Next element

Of course, if you provided information on exactly how you are getting the
information to place in the array, others more knowledgeable than I would be
able to provide you with some more concrete information.

Bruce

"Joe" <jo*****@tlen.p lwrote in message
news:11******** **************@ m58g2000cwm.goo glegroups.com.. .
hi. simple question: how can one declare Array (or table) with unknown
number of elements, and then assign values to it, example:

Dim TableStrings() as String

TableStrings(0) = "first value"
TableStrings(1) = "second"
TableStrings(2) = "tird" .... etc
?

Feb 26 '07 #3
Joe
On Feb 25, 6:46 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrot e:
"Joe" <joe1...@tlen.p lschrieb:
You may want to use 'System.Collect ions.Generic.Li st(Of T)'.
ok, but later on, how can I read n-element from x element list (f.e. I
want to read 5th one?
Feb 26 '07 #4
On 2007-02-26, Joe <jo*****@tlen.p lwrote:
On Feb 25, 6:46 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrot e:
>"Joe" <joe1...@tlen.p lschrieb:
You may want to use 'System.Collect ions.Generic.Li st(Of T)'.

ok, but later on, how can I read n-element from x element list (f.e. I
want to read 5th one?

dim i as integer = theList(4)

HTH
--
Tom Shelton
Feb 26 '07 #5
Joe
On Feb 25, 8:22 pm, Tom Shelton <tom_shel...@co mcastXXXXXXX.ne t>
wrote:
On 2007-02-26, Joe <joe1...@tlen.p lwrote:
On Feb 25, 6:46 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrot e:
"Joe" <joe1...@tlen.p lschrieb:
You may want to use 'System.Collect ions.Generic.Li st(Of T)'.
ok, but later on, how can I read n-element from x element list (f.e. I
want to read 5th one?

dim i as integer = theList(4)

HTH
--
Tom Shelton

thank you very much, everything clear now :)

Feb 26 '07 #6
Joe,

If you are going to be using arrays, take a look at
REDIM and the PRESERVE command.

Miro

"Joe" <jo*****@tlen.p lwrote in message
news:11******** **************@ h3g2000cwc.goog legroups.com...
On Feb 25, 8:22 pm, Tom Shelton <tom_shel...@co mcastXXXXXXX.ne t>
wrote:
>On 2007-02-26, Joe <joe1...@tlen.p lwrote:
On Feb 25, 6:46 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrot e:
"Joe" <joe1...@tlen.p lschrieb:
You may want to use 'System.Collect ions.Generic.Li st(Of T)'.
ok, but later on, how can I read n-element from x element list (f.e. I
want to read 5th one?

dim i as integer = theList(4)

HTH
--
Tom Shelton


thank you very much, everything clear now :)

Feb 26 '07 #7
"Miro" <mi******@golde n.netwrote in news:u3sUI$aWHH A.4964
@TK2MSFTNGP06.p hx.gbl:
If you are going to be using arrays, take a look at
REDIM and the PRESERVE command.
Redim Preserve is very inefficent so it is be better to use a Generic.List
as Herfried mentioned or an arraylist. Both can be converted to an array
using the ToArray function.

http://weblogs.asp.net/eporter/archi.../07/22943.aspx
Feb 26 '07 #8
or take a look at the array class
Dim x(1) As Integer ' create instance with one element

For i As Integer = 1 To 10

Array.Resize(x, x.Length + i) ' add some elements during runtime

Next

' to proof that it works

For Each i As Integer In x

Debug.WriteLine (i.ToString) ' writes out all zero`s for every element

Next

ofcourse you could do the above example with anny type you want

regards

Michel Posseth

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.atschre ef in bericht
news:%2******** *******@TK2MSFT NGP06.phx.gbl.. .
"Joe" <jo*****@tlen.p lschrieb:
>hi. simple question: how can one declare Array (or table) with unknown
number of elements, and then assign values to it, example:

Dim TableStrings() as String

TableStrings(0 ) = "first value"
TableStrings(1 ) = "second"
TableStrings(2 ) = "tird" .... etc

You may want to use 'System.Collect ions.Generic.Li st(Of T)'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Feb 26 '07 #9
Michel,

I am 100% sure that Herfried this knows.

Cor

"Michel Posseth [MCP]" <ms****@posseth .comschreef in bericht
news:up******** *****@TK2MSFTNG P05.phx.gbl...
or take a look at the array class
Dim x(1) As Integer ' create instance with one element

For i As Integer = 1 To 10

Array.Resize(x, x.Length + i) ' add some elements during runtime

Next

' to proof that it works

For Each i As Integer In x

Debug.WriteLine (i.ToString) ' writes out all zero`s for every element

Next

ofcourse you could do the above example with anny type you want

regards

Michel Posseth

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.atschre ef in bericht
news:%2******** *******@TK2MSFT NGP06.phx.gbl.. .
>"Joe" <jo*****@tlen.p lschrieb:
>>hi. simple question: how can one declare Array (or table) with unknown
number of elements, and then assign values to it, example:

Dim TableStrings() as String

TableStrings( 0) = "first value"
TableStrings( 1) = "second"
TableStrings( 2) = "tird" .... etc

You may want to use 'System.Collect ions.Generic.Li st(Of T)'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


Feb 26 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3845
by: HateSpam | last post by:
Using Visual Studio .NET version of Visual Basic. I am defining a class that has, as a member, an array of another user-defined class. private mBoard as CBoardPosition() The problem comes when I attempt to size the array, it should be an 8x8 grid. When I use:
8
427
by: User | last post by:
Hi, This is very basic, It may be a repost, if so I'm sorry. The problem is that this declaration : Private strMyArray(100) As String will create an array of string with a length of 101, but the length should be only of 100 (0 to 99).
0
1331
by: Dr. Zharkov | last post by:
We have program Visual Basic .NET 2003 for construction of 3D-Graphics as a surface z=f (x, y). From VB .NET 2003 we want to transfer coordinates of this surface as myArrayVB (2000, 1) in myArrayVó of VC++ .NET 2003 on scheme of "component - client". But there are error 1 and error 2. For development of a component in VB .NET 2003 we make: File, New, Project, Visual Basic Projects, Class Library, name of project: ComponentVB. We write...
6
24584
by: Christian Blackburn | last post by:
Hi Gang, I can't seem to figure out how to create an object array in VB.NET 2003. In VB6 you would just select an object copy and paste it and that was that. I don't know why in the heck they decided to change that. I thought it was great. I assume a 2002 answer would work in 2003 as well. Can somebody tell me how to create an object array or point me to an MSDN article regarding it? Thanks, Christian Blackburn
11
2199
by: Dr. Zharkov | last post by:
We want to export myArrayVB (2000, 2) of VB .NET 2003 in myArrayVó of VC++ .NET 2003 on scheme "component - client". But there is an error. For development of a component in VB .NET 2003 we make: File, New, Project, Visual Basic Projects, Class Library, name of project: ComponentVB. We write the code: Public Function myFunction1(ByVal N_i As Integer, _
20
2379
by: samean | last post by:
Hello, Could you explain me,In VB6 using control array,and how about VB.net. Thanks
5
5025
by: juan | last post by:
Hello, I have a web project in Visual Basic 2005. I want to create a session variable in the "global.asax" file as an array of strings type. The syntax I use is the following: Session("MyArray")(10, 10) = "" but I get an error. I think that I don't know the syntax correctly. Someone knows it? Thanks, John.
7
2880
by: André | last post by:
Hi, I need several cookies depending of an variable (x), so i defined a HttpCookie() as an array. My problems: 1)I get the error: Object reference not set to an instance of an object. 2)My second question is: how to request those cookies, because there is no name? Thanks
6
6968
by: ashokbio | last post by:
I want to create an associative array, similar to PERL language, using Visual Basic 6. Example: Using PERL %A = ("A"=>"Apple","B"=>"Banana"); i.e., A is associated to the word Apple and B is associated to the word Banana. The alternative conversion is: $A{'A'} = "Apple"; $A{'B'} = "Banana";
0
8168
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8672
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8614
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8330
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4167
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2603
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.