+ Reply to Thread
Results 1 to 5 of 5

Vba arrays declaration.

  1. #1
    Registered User
    Join Date
    09-29-2011
    Location
    Madrid, spain
    MS-Off Ver
    Excel 2003
    Posts
    2

    Vba arrays declaration.

    Hello,
    I'm new to this forum and i have not presented myself. If that is rude i'sorry.

    Im developing an app over vba-excel.

    My question is, can i declare 2 or more arrays on the same line, like:

    Dim arr(), arr2(), arr3() as integer

    Im used to do that with variables but i seem to have problems if i do it with arrays.

    I dont seem to have problems with:


    Dim vble,vble2, arr3() as integer

    I would like some clarification and thanks in advance

    Yours metafisica.

  2. #2
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Vba arrays declaration.

    Welcome to the forum.

    You can, but you need to be aware of the data types.

    In VBA, when you declare your variables:
    Please Login or Register  to view this content.
    This line actually defines a and b as Variants and c as an Integer.

    To declare all three as Integer types, you need to do it like this:
    Please Login or Register  to view this content.

    Similarly, for your line of code here:
    Please Login or Register  to view this content.
    If you want all three to be Integer arrays, you need to use:
    Please Login or Register  to view this content.

    If you continue to have problems, please post back with the specifics.
    Hope that helps,

    Colin

    RAD Excel Blog

  3. #3
    Registered User
    Join Date
    09-29-2011
    Location
    Madrid, spain
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Vba arrays declaration.

    Good night (spanish time)
    Thank you very much for your fast and accurate reply.

    That explains why sometimes i have problems and smtimes not. It can be a problem when vb offers that much flexibility. I was defining variants and on most times it works but it gives space for trouble.

    It remebers me the time when i wasnt using "option explicit". It was great fun whenever i misspelled a vble name and it automatically defined a new one.

    Again thanks, u just got yourself a free beer (or soda if you fancy) when u come to Madrid.
    Yours metafisica.

  4. #4
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Vba arrays declaration.

    I'm delighted to hear you're using Option Explicit and next time I am in Madrid I will take you up on the beer!

    If you're happy with the answer provided, please mark your thread as solved. Thanks.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Vba arrays declaration.

    A craven solitation for Demon Rum, Mr Legg -- for shame!
    Entia non sunt multiplicanda sine necessitate

+ 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