473,385 Members | 1,958 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,385 software developers and data experts.

"Basic Question"

What is the difference between these declarations:
Dim strMyData() as string

and

Dim strMyData as string()

-Peter

Nov 21 '05 #1
12 1246
I believe they are equivalent. I think the second has been deprecated.
Although, it works fine in VB 2005 beta 1.

Dim strMyData() As String = {"a", "b", "c"}
Dim strMyData As String() = {"a", "b", "c"}

Greg
"pmclinn" <pe***@mclinn.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
What is the difference between these declarations:
Dim strMyData() as string

and

Dim strMyData as string()

-Peter

Nov 21 '05 #2
Peter,

As Greg said they have equal results,

However
dim str(10) as String goes and
dim str() as String(10) does not go

A little bit confusing is that in a function or other places where you need
the type you will write:
private function myfunction (byval str as String()) As string()
Ctype(mytype, String())

I hope this helps?

Cor

"pmclinn" <pe***@mclinn.com>
What is the difference between these declarations:
Dim strMyData() as string

and

Dim strMyData as string()

-Peter

Nov 21 '05 #3
"Cor Ligthert" <no************@planet.nl> schrieb:
As Greg said they have equal results,

However
dim str(10) as String goes and
dim str() as String(10) does not go


But 'Dim astr As String(10) {}' will work.

--
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
Herfried,
But 'Dim astr As String(10) {}' will work.


Thanks I did not know that.
(And I will never use that)

:-)

Cor
Nov 21 '05 #5
Don't write that one off to quickly Cor.

Although it's not quite the same, the following can be very useful.

Dim astr() As String
Nov 21 '05 #6
"Stephany Young" <noone@localhost> schrieb:
Although it's not quite the same, the following can be very useful.

Dim astr() As String
.
.
.
astr = New String(10) {}


You could use 'ReDim astr(10)' instead of the line above, which is IMO the
preferred method because it uses VB.NET's own array syntax.

--
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 #7
Stephany,

I have the opinion that for a fixed array the array is the best
For a dynamimc array every Ilist or Icollection implementing
array/collection, where the arraylist is my favorit.

Cor
Nov 21 '05 #8
Agreed Herfied. I was pointing out a valid alternative rather than
advocating it's use.

That said, the alternative does have one useful feature and that is to
populate the array at the same time as declaring and/or 'ReDim'ing it:

Dim astr() As String = New String(10) {"1", "4", "7" ... "A", "D"}
Nov 21 '05 #9
Dim strMyData() as string

means that you are initializing an array of strings

Dim strMyData as string()

is simply wrong syntax. The open and close parentheses at the end of the
statement signifies that you are providing reference to the class
through the default constructor of the class but since you are not using
it with the New keyword it is wrong syntax.

You can use Dim strMyData as New SomeClass(), which means that you are
creating an instance called strMyData and initializing the object
through the default constructor of the class.

with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #10
> Dim strMyData as string() is simply wrong syntax. is simply wrong syntax.

Don't be so sure. I still think it is just depracted syntax.

Try this:

Dim s as string
Intellisense says for s = "Dim s as string"

Dim s() as string
Intellisense says for s = "Dim s() as string"

Dim s as string()
Intellisense says for s = "Dim s() as string"

Also this will compile:
Dim s as string()
Redim s(10)

And this won't:
Dim s a string
Redim s(10)

Greg

"Ravichandran J.V." <jv************@yahoo.com> wrote in message
news:O$**************@TK2MSFTNGP15.phx.gbl...
Dim strMyData() as string

means that you are initializing an array of strings

Dim strMyData as string()

is simply wrong syntax. The open and close parentheses at the end of the
statement signifies that you are providing reference to the class
through the default constructor of the class but since you are not using
it with the New keyword it is wrong syntax.

You can use Dim strMyData as New SomeClass(), which means that you are
creating an instance called strMyData and initializing the object
through the default constructor of the class.

with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #11
Greg,

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> schrieb_
Dim strMyData as string() is simply wrong syntax. is simply wrong syntax.


Don't be so sure. I still think it is just depracted syntax.


I don't think it's deprecated. It's only an alternative that works and that
will work for forseeable future. VB6 only supported the 'Dim X() As Y'
syntax.

--
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 #12

"Ravichandran J.V." <jv************@yahoo.com> wrote
Dim strMyData() as string

means that you are initializing an array of strings

Dim strMyData as string()

is simply wrong syntax. The open and close parentheses at the end of the
statement signifies that you are providing reference to the class
through the default constructor of the class but since you are not using
it with the New keyword it is wrong syntax.


You might want to inform MSFT that syntax is wrong since they
use that syntax in the documentation to explain creating an array!

(See 'New keyword' in VB.Net help)

There is no parameterless constructor for the String class:

strMyData = New String()

That syntax is wrong, which indicates that there is no 'default constructor'
for the String class.

Following primative types with parentheses is another valid data type as
evidensed by:

Dim a As String() = {"X", "Y"}
Dim b As Integer() = {1, 2}

The parentheses indicate the Array class is used to build a strongly typed
array. (Note the array class also has no 'default constructor' and the
desired type is a requirement of the shared CreateInstance method.)

HTH
LFS

Nov 21 '05 #13

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

Similar topics

1
by: bidalah | last post by:
Hello, I am looking for basic info on installing and using MSDE. I am trying to install and play with MSDE on my PC (Win2000). I finally managed to work my way through installation, and named...
18
by: steve | last post by:
I'm trying to create a structure of three pointers to doubles. For which I have: typedef struct { double *lst_t, *lst_vc, *lst_ic; } last_values; I then need to allocate space for...
3
by: Keith Rebello | last post by:
I have an object called ColumnSection which represents a reinforced concrete column. This object contains an arraylist called Diagrams which contains Graph2D objects which are essentially X-Y...
1
by: Ottavio | last post by:
Hello, I'm having some problems with the authentication during a web service call I know I have to add the "Authorization: Basic xxxxxxxx" in the http header (not soap header) but I can't find a...
43
by: Bill H | last post by:
25 years ago every computer came with some form of Basic interpreter so you could use yoru computer without having to buy more software. Is Javascript (teamed with HTML) set to become the new...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.