Consulting

Results 1 to 3 of 3

Thread: Array Question - basic

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Banned VBAX Contributor
    Joined
    Aug 2017
    Posts
    144
    Location

    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 Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    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)
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    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


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    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) / 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
  •