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

Dim lbl( ) As Label = New Label( ){...} vs Dim lbl( ) As Label = {...}

Ron
Hello,

I created an array of label controls like this:

Dim lbl() As Label = {Me.lbl1, Me.lbl2, Me.lbl3}

and was able to iterate through the array. But then I saw
another way to declare the same array:

Dim lbl() As Label = New Label(){Me.lbl1, Me.lbl2, Me.lbl3}

Both ways seems to work fine, but I want to get in the
practice of doing this correctly. Is there a difference
between using New or not for this? If so, what is the
difference?

Thanks,
Ron
Nov 21 '05 #1
4 4906
"Ron" <an*******@discussions.microsoft.com> schrieb:
I created an array of label controls like this:

Dim lbl() As Label = {Me.lbl1, Me.lbl2, Me.lbl3}

and was able to iterate through the array. But then I saw
another way to declare the same array:

Dim lbl() As Label = New Label(){Me.lbl1, Me.lbl2, Me.lbl3}

Both ways seems to work fine, but I want to get in the
practice of doing this correctly. Is there a difference
between using New or not for this? If so, what is the
difference?


There is no difference. I would prefer the first solution because of the
higher readability.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #2
"Ron" <an*******@discussions.microsoft.com> schrieb:
I created an array of label controls like this:

Dim lbl() As Label = {Me.lbl1, Me.lbl2, Me.lbl3}

and was able to iterate through the array. But then I saw
another way to declare the same array:

Dim lbl() As Label = New Label(){Me.lbl1, Me.lbl2, Me.lbl3}

Both ways seems to work fine, but I want to get in the
practice of doing this correctly. Is there a difference
between using New or not for this? If so, what is the
difference?


There is no difference. I would prefer the first solution because of the
higher readability.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #3
Ron,
As Herfried suggests I normally use the first syntax, however you need the
second syntax when you want an array, but you don't want or need the
variable.

For example:

Sub Test(labels() As Label)
End Sub

Test(New Label(){Me.lbl1, Me.lbl2, Me.lbl3})

Here I want to send an array of Labels to the Test method, however I don't
want or need an array variable to hold them.

Hope this helps
Jay

"Ron" <an*******@discussions.microsoft.com> wrote in message
news:63****************************@phx.gbl...
Hello,

I created an array of label controls like this:

Dim lbl() As Label = {Me.lbl1, Me.lbl2, Me.lbl3}

and was able to iterate through the array. But then I saw
another way to declare the same array:

Dim lbl() As Label = New Label(){Me.lbl1, Me.lbl2, Me.lbl3}

Both ways seems to work fine, but I want to get in the
practice of doing this correctly. Is there a difference
between using New or not for this? If so, what is the
difference?

Thanks,
Ron

Nov 21 '05 #4
Ron,
As Herfried suggests I normally use the first syntax, however you need the
second syntax when you want an array, but you don't want or need the
variable.

For example:

Sub Test(labels() As Label)
End Sub

Test(New Label(){Me.lbl1, Me.lbl2, Me.lbl3})

Here I want to send an array of Labels to the Test method, however I don't
want or need an array variable to hold them.

Hope this helps
Jay

"Ron" <an*******@discussions.microsoft.com> wrote in message
news:63****************************@phx.gbl...
Hello,

I created an array of label controls like this:

Dim lbl() As Label = {Me.lbl1, Me.lbl2, Me.lbl3}

and was able to iterate through the array. But then I saw
another way to declare the same array:

Dim lbl() As Label = New Label(){Me.lbl1, Me.lbl2, Me.lbl3}

Both ways seems to work fine, but I want to get in the
practice of doing this correctly. Is there a difference
between using New or not for this? If so, what is the
difference?

Thanks,
Ron

Nov 21 '05 #5

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

Similar topics

3
by: TR | last post by:
Is it possible with CSS to prevent this wrapping alignment with a checkbox with a nested label? This is the label of the checkbox that wraps beneath it I'd prefer it looked like...
3
by: kaiser | last post by:
Hello, Am new to C# and am playing around trying to get a while loop to display a int on a windows console using label. private void btnGo_Click(object sender, System.EventArgs e) { int Counter...
2
by: Shapper | last post by:
Hello, I am creating a contact form in ASP.NET and I need to access the labels on Page_Load on my aspx.vb file. The other elements such as input box and text box don't need to be accessible....
7
by: anthony | last post by:
I know this is probably talk about millions of time here, but I cant seem to find a close one, I am so used to the vb6 control array, now that I have to use vb.net for my project, I like to do...
4
by: Phil | last post by:
Hi, How to add programmatically a label into a content page? I tried this but doesn't work: Thanks Phil content page:
0
by: anniejacob | last post by:
hi, i want to drag n drop a label from 1 panel to other , when it is dragged to the other panel i want it 2 create another label there in panel2. i hav written the below code . public partial...
0
by: CSharpner | last post by:
How can I do the following?: Have a label on a form have its Text property bound to a setting from one of my DLL library's config files? I've followed these instructions to successfully get...
2
by: THEAF | last post by:
hi, i'm tryin to create this math questions form for my sister. the form has 2 labels where random numbers show, a text box where the answer is entered, a next button the next numbers and an exit...
1
by: karthik25 | last post by:
Hi, The following code creates a tab container, 5 tab panels, buttons, labels. I was able to add event handlers to the button. But how am i supposed to access the dynamically created labels? For...
1
by: jagdeep gupta | last post by:
Thanks a lot friend but a problem does occur is i have added a br tag as well but it is not shown in output plz check: TextBox textBoxArr; Label lbl=new Label; Label lblbr=new Label(); ...
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...
1
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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
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
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.