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

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Ron (anonymous_at_discussions.microsoft.com)
Date: 11/12/04


Date: Fri, 12 Nov 2004 09:04:04 -0800

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



Relevant Pages

  • Re: Passing an array of structuresfrom a pointer?
    ... to only declare structs in headers and then define the ... the struct should be declared ... what if you have a simple array like this: ... In the header we would declare? ...
    (microsoft.public.vc.language)
  • Re: vb.net class
    ... about fixed array lenghts or using ReDim statements. ... code ensures everything in the array is a String because you declare it ... Count can be generated from the time list, not need to store ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Issue designing a class module that uses OleLoadPicture
    ... There is a private sub that works on the byte array using the api ... Declare Function OleLoadPicture1 Lib "oleaut32" Alias ... Private m_hAccess As Long ... 'Device context for Access ...
    (comp.databases.ms-access)
  • Re: Scope of Variant / Array
    ... Even though you declared the array "public" in the main (parent) form, ... a form code module is the same as a class module. ... Constants, fixed-length strings, arrays, user-defined types and Declare ...
    (microsoft.public.access.formscoding)
  • Re: ReDim not working as expected. Array expert needed.
    ... Any dimensions you declare your variable in are wiped out, ... variable as a variant, I next told you not to redim it. ... examples of how array dimensions work in VBA. ...
    (microsoft.public.excel.programming)