PC Review


Reply
Thread Tools Rate Thread

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

 
 
Ron
Guest
Posts: n/a
 
      12th Nov 2004
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
 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      12th Nov 2004
"Ron" <(E-Mail Removed)> 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/>

 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      12th Nov 2004
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" <(E-Mail Removed)> wrote in message
news:639701c4c8d9$9cfe81c0$(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access 2003 Label Report - Text Position On Label Question Dermot Microsoft Access Reports 7 4th Dec 2008 01:06 AM
Word prints label in center of page instead of on select label =?Utf-8?B?R01vbQ==?= Microsoft Word Document Management 1 30th Aug 2006 08:23 PM
adding a new color label to the label list for Microsoft Outlook 2 =?Utf-8?B?Q1NTIFRlY2g=?= Microsoft Outlook Calendar 1 21st Jul 2006 04:57 PM
Receiving #error when creating mailing label using label wizard =?Utf-8?B?RGVlX0RlZQ==?= Microsoft Access 2 1st Dec 2005 01:36 PM
How to change mailing label size in existing label document =?Utf-8?B?R3Jhbm55QW5u?= Microsoft Word Document Management 1 2nd Dec 2004 05:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:10 PM.