473,320 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Redim array VB6 to dotnet

Hi
In VB 6 I would declare an array in the general part to make it visible to
all parts then once I know how elements I had I would redim it with the
amount thus

Dim testarray() as string

.......
.......

Redim testarray(9) as string

How do I do this in VB.Net?

Thanks
Nov 21 '05 #1
6 11012
Easiest way to do this in VB.NET is to use an ArrayList object. This is an
array that has an Add method so you don't have to redim it. It grows as you
needed. Otherwise, you can just use the ReDim keyword like your use to.

Dim S() as String
ReDim S(9)

Chris
"Adrian" <Ad****@nospamhotmail.com.uk> wrote in message
news:cs**********@hercules.btinternet.com...
Hi
In VB 6 I would declare an array in the general part to make it visible to
all parts then once I know how elements I had I would redim it with the
amount thus

Dim testarray() as string

......
......

Redim testarray(9) as string

How do I do this in VB.Net?

Thanks

Nov 21 '05 #2
"Adrian" <Ad****@nospamhotmail.com.uk> schrieb:
In VB 6 I would declare an array in the general part to make it visible to
all parts then once I know how elements I had I would redim it with the
amount thus

Dim testarray() as string

......
......

Redim testarray(9) as string

How do I do this in VB.Net?


It works the same, but you'll have to remove the 'As String' on the 'ReDim'
statement. Notice that 9 is treated as the upper-bound of the new array, so
the array will hold 10 items with indices 0 through 9.

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

Nov 21 '05 #3
Also keep in mind that when you redim the array - you will lose the contents
unless you use the preserve keyword to maintain the contents. You may want
to look into using the ArrayList class rather than using a standard array
since this grows as needed plus you can sort and so on.

Brian Patterson
http://dotnet.redeyepos.com

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:es**************@TK2MSFTNGP10.phx.gbl...
"Adrian" <Ad****@nospamhotmail.com.uk> schrieb:
In VB 6 I would declare an array in the general part to make it visible
to all parts then once I know how elements I had I would redim it with
the amount thus

Dim testarray() as string

......
......

Redim testarray(9) as string

How do I do this in VB.Net?


It works the same, but you'll have to remove the 'As String' on the
'ReDim' statement. Notice that 9 is treated as the upper-bound of the new
array, so the array will hold 10 items with indices 0 through 9.

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

Nov 21 '05 #4
"Brian Patterson" <br********************@mchsi.com> schrieb:
Also keep in mind that when you redim the array - you will lose the
contents unless you use the preserve keyword to maintain the contents.
You may want to look into using the ArrayList class rather than using a
standard array since this grows as needed plus you can sort and so on.


I didn't specifically mention 'Preserve' because the behavior didn't change
between VB6 and VB.NET. You can easily sort normal arrays too using
'Array.Sort' too. Arrays give you easy-to-use type-safety, arraylists
don't. If the number of items stored in the array rarely changes, using an
array is the preferred way. Alternatively, implementing a type-safe
collection or waiting for generic collection classes of Whidbey may be an
option if type-safety is a requirement and you want to get rid of tons of
'DirectCast' statements in your code.

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

Nov 21 '05 #5
Many thanks to you all, its been of great help.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OE**************@TK2MSFTNGP11.phx.gbl...
"Brian Patterson" <br********************@mchsi.com> schrieb:
Also keep in mind that when you redim the array - you will lose the
contents unless you use the preserve keyword to maintain the contents.
You may want to look into using the ArrayList class rather than using a
standard array since this grows as needed plus you can sort and so on.


I didn't specifically mention 'Preserve' because the behavior didn't
change between VB6 and VB.NET. You can easily sort normal arrays too
using 'Array.Sort' too. Arrays give you easy-to-use type-safety,
arraylists don't. If the number of items stored in the array rarely
changes, using an array is the preferred way. Alternatively, implementing
a type-safe collection or waiting for generic collection classes of
Whidbey may be an option if type-safety is a requirement and you want to
get rid of tons of 'DirectCast' statements in your code.

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

Nov 21 '05 #6
Adrian,

I completly agree with Chris and Brian,

Maybe that helps

Cor
Nov 21 '05 #7

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

Similar topics

2
by: Wayne Wengert | last post by:
I am trying to add one column to an existing array (code below). The ReDim command gives the error: ----------------------------------------------- Microsoft VBScript runtime error '800a0009' ...
2
by: | last post by:
Is it correct to think that after reducing the populated array's size from say, 10 to 5 with redim preserve myArray(i) an attempt to access an element above the fifth does not cause a...
2
by: Andreas Müller | last post by:
Hi all, VB.NET has the "Redim " statement, which allows me to redimension a System.Array to a new size. I was wondering if something like that is build into the C# language, too? Thanks in...
6
by: LP | last post by:
Hello, What is C# equivalent of rediming an array and preserving exciting elements. VB.NET syntax looks something like this: ReDim Preserve myArray(5) Thank you
8
by: John A Grandy | last post by:
redim may no longer be used in vb.net ... is there another way to change at the runtime the lower & upper bounds of an array ?
6
by: John A Grandy | last post by:
inside a procedure , i code Dim values(1) As Object .... various other lines of code ... ReDim values(2) As Object
9
by: John A Grandy | last post by:
In VB6 you could get away with the following code: Dim Index As Integer Dim ItemsCount As Integer Dim StringArray() As String Dim StringValue As String '....
5
by: Paul | last post by:
Off the cuff, does anyone know if arraylist is more efficeint at adding items to an array than redim preserve? Paul <begin loop> Dim c As Integer = SomeArray.GetUpperBound(0) + 1 ReDim...
19
by: Tom Jastrzebski | last post by:
Hello, I was just testing VB.Net on Framework.Net 2.0 performance when I run into the this problem. This trivial code attached below executed hundreds, if not thousand times faster in VB 6.0...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.