Consulting

Results 1 to 3 of 3

Thread: Array Question - basic

  1. #1

    Thumbs up Array Question - basic

    Hi Team

    I know array start with zero by default, by declaring option base1 it will start from 1 ,

    is it possible to start an array from 2?... plz help new in array



    Regards,
    Mallesh

  2. #2
    Moderator VBAX Wizard SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    6,840
    Location
    Dim myArray(2 to 10)
    Dim SomeVariable As Variant
    Dim OtherVar(1 to 10, 1 to 10) 
    ReDim SomeVariable(2 to 20)
    Redim OtherVar(2 to 11, 2 to 11)
    Please take the time to read the Forum FAQ

  3. #3
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    5,931
    Location
    You can (as Sam said) start arrays at any start/end

    The Option Base is for when you do NOT explicitly specify

    So if you can pick your bounds correctly, you can make life easier. You should use LBound and UBound

    Example: working with rows 16 to 32

    Dim A (16 to 32) as Long
    
    For r = LBound(A) to UBound(A)
        Cells(r,1).Value = 2*Cells(r,2)
    Next r

    or even use enumerations

    Dim D(vbSunday to vbSaturday)

    If you define your own enumerations, it does help readability

    Enum colNames
        FName =12
        LName = 13
        Addr = 14
    End Enum
    
    Dim N(FName to Addr)
    Paul

    ------------------------------------------------------------------------------------------------------------------------
    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s)
    (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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