+ Reply to Thread
Results 1 to 5 of 5

Dim MyArray() as Long, Dim MyArray() as String, etc.

  1. #1
    quartz
    Guest

    Dim MyArray() as Long, Dim MyArray() as String, etc.

    I am using Office 2003 on Windows XP.

    I am used to just dimensioning my arrays a variants (since I think at one
    time you had to?), but can you not now dim them as other types? Or does VBA
    coerce them back to variants anyway? For example:

    Dim arrRow() As Long
    Dim arrFileName() As String

    Is there any performance gain in doing this?
    Is there any other advantage in doing this?
    Is it considered good programming practice to do this?

    Any an all input appreciated.
    Thanks in advance.

  2. #2
    Nick
    Guest

    Re: Dim MyArray() as Long, Dim MyArray() as String, etc.

    It's always been good practice to be specific in any variable declaration
    unless you are unsure what value will be passed to it.
    You may have been having problems in the past because you are declaring an
    array without any dimensions. If you do this with a variant you don't have
    to ReDim it to increase the dimension size.
    If you want to use a specific type you must redim it to specify the
    dimensions when the code is running



    "quartz" <[email protected]> wrote in message
    news:[email protected]...
    >I am using Office 2003 on Windows XP.
    >
    > I am used to just dimensioning my arrays a variants (since I think at one
    > time you had to?), but can you not now dim them as other types? Or does
    > VBA
    > coerce them back to variants anyway? For example:
    >
    > Dim arrRow() As Long
    > Dim arrFileName() As String
    >
    > Is there any performance gain in doing this?
    > Is there any other advantage in doing this?
    > Is it considered good programming practice to do this?
    >
    > Any an all input appreciated.
    > Thanks in advance.




  3. #3
    quartz
    Guest

    Re: Dim MyArray() as Long, Dim MyArray() as String, etc.

    Nick,
    I appreciate your input, but I know about array sizes. My programs almost
    always call for dynamic arrays. My real focus was on determining if there is
    an advantage to dimensioning an array as a type other than variant. Any
    further input on this?

    "Nick" wrote:

    > It's always been good practice to be specific in any variable declaration
    > unless you are unsure what value will be passed to it.
    > You may have been having problems in the past because you are declaring an
    > array without any dimensions. If you do this with a variant you don't have
    > to ReDim it to increase the dimension size.
    > If you want to use a specific type you must redim it to specify the
    > dimensions when the code is running
    >
    >
    >
    > "quartz" <[email protected]> wrote in message
    > news:[email protected]...
    > >I am using Office 2003 on Windows XP.
    > >
    > > I am used to just dimensioning my arrays a variants (since I think at one
    > > time you had to?), but can you not now dim them as other types? Or does
    > > VBA
    > > coerce them back to variants anyway? For example:
    > >
    > > Dim arrRow() As Long
    > > Dim arrFileName() As String
    > >
    > > Is there any performance gain in doing this?
    > > Is there any other advantage in doing this?
    > > Is it considered good programming practice to do this?
    > >
    > > Any an all input appreciated.
    > > Thanks in advance.

    >
    >
    >


  4. #4
    Tom Ogilvy
    Guest

    Re: Dim MyArray() as Long, Dim MyArray() as String, etc.

    Yes, there should be advantages in size and speed.

    --
    Regards,
    Tom Ogilvy


    "quartz" <[email protected]> wrote in message
    news:[email protected]...
    > Nick,
    > I appreciate your input, but I know about array sizes. My programs almost
    > always call for dynamic arrays. My real focus was on determining if there

    is
    > an advantage to dimensioning an array as a type other than variant. Any
    > further input on this?
    >
    > "Nick" wrote:
    >
    > > It's always been good practice to be specific in any variable

    declaration
    > > unless you are unsure what value will be passed to it.
    > > You may have been having problems in the past because you are declaring

    an
    > > array without any dimensions. If you do this with a variant you don't

    have
    > > to ReDim it to increase the dimension size.
    > > If you want to use a specific type you must redim it to specify the
    > > dimensions when the code is running
    > >
    > >
    > >
    > > "quartz" <[email protected]> wrote in message
    > > news:[email protected]...
    > > >I am using Office 2003 on Windows XP.
    > > >
    > > > I am used to just dimensioning my arrays a variants (since I think at

    one
    > > > time you had to?), but can you not now dim them as other types? Or

    does
    > > > VBA
    > > > coerce them back to variants anyway? For example:
    > > >
    > > > Dim arrRow() As Long
    > > > Dim arrFileName() As String
    > > >
    > > > Is there any performance gain in doing this?
    > > > Is there any other advantage in doing this?
    > > > Is it considered good programming practice to do this?
    > > >
    > > > Any an all input appreciated.
    > > > Thanks in advance.

    > >
    > >
    > >




  5. #5
    Nick
    Guest

    Re: Dim MyArray() as Long, Dim MyArray() as String, etc.

    No problem.

    Specifying type is faster as VB doesn't have to coerce the variable to the
    data type once the data has been entered and also it uses less memory If you
    are specific the system allocates only the memory required for the data
    type. If you use variant it sets aside much more memory as it doesn't know
    what will be passed



    "quartz" <[email protected]> wrote in message
    news:[email protected]...
    > Nick,
    > I appreciate your input, but I know about array sizes. My programs almost
    > always call for dynamic arrays. My real focus was on determining if there
    > is
    > an advantage to dimensioning an array as a type other than variant. Any
    > further input on this?
    >
    > "Nick" wrote:
    >
    >> It's always been good practice to be specific in any variable declaration
    >> unless you are unsure what value will be passed to it.
    >> You may have been having problems in the past because you are declaring
    >> an
    >> array without any dimensions. If you do this with a variant you don't
    >> have
    >> to ReDim it to increase the dimension size.
    >> If you want to use a specific type you must redim it to specify the
    >> dimensions when the code is running
    >>
    >>
    >>
    >> "quartz" <[email protected]> wrote in message
    >> news:[email protected]...
    >> >I am using Office 2003 on Windows XP.
    >> >
    >> > I am used to just dimensioning my arrays a variants (since I think at
    >> > one
    >> > time you had to?), but can you not now dim them as other types? Or does
    >> > VBA
    >> > coerce them back to variants anyway? For example:
    >> >
    >> > Dim arrRow() As Long
    >> > Dim arrFileName() As String
    >> >
    >> > Is there any performance gain in doing this?
    >> > Is there any other advantage in doing this?
    >> > Is it considered good programming practice to do this?
    >> >
    >> > Any an all input appreciated.
    >> > Thanks in advance.

    >>
    >>
    >>




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1