Results 1 to 6 of 6

Thread: [RESOLVED] Possible combinations in single dimension array

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2014
    Posts
    3

    Resolved [RESOLVED] Possible combinations in single dimension array

    Hi all



    i have an array a(5) with OLNY 2 digits

    I need to take ALL possible combinations.. like

    11112
    11211
    22211
    22111
    11111
    22222
    21212

    ect..


    or better with 0 & 1

    00001
    11000
    10101

    ect..

    is it possible to do this with vb command ..... format("####1",x") ?


    any idea wellcome!
    Last edited by MasterGR; Sep 18th, 2014 at 02:54 PM.

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Possible combinations in 2d array

    First, a(5) is not a 2D array, it's a single dimension array with 6 entries, 0 to 5

    Second, you say with only 2 digits but you are showing 5 digits.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2014
    Posts
    3

    Re: Possible combinations in 2d array

    ok my false... single dimension array

    a(5) where a(1)=0 , a(2)=0 , a(3)=0 , a(4)=0 , a(5)=1 , unused a(0)

    possible combinations

    00001
    00010
    00011
    01110
    ect.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Possible combinations in single dimension array

    Welcome to the forums

    Suggestion: search this forum for the key word: permutations
    You will find quite a bit info on this
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Possible combinations in single dimension array

    If it's only for "powers of two" Bit-Representations, then there's IMO no need to fiddle around with an array.

    e.g. the 5Bit-combinations you're apparently after, can be printed out this way
    (directly from an integer-value with nBits=5 in a small loop):

    Code:
    Private Sub Form_Load()
    Dim L As Long, nBits As Long
      nBits = 5
      For L = 0 To 2 ^ nBits - 1
        Debug.Print L, GetBitString(L, nBits)
      Next
    End Sub
     
    Function GetBitString(ByVal L As Long, ByVal nBits As Long) As String
    Dim i As Long
      For i = 0 To nBits - 1
       GetBitString = (L And 1) & GetBitString: L = L \ 2
      Next
    End Function
    Olaf

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2014
    Posts
    3

    Re: Possible combinations in single dimension array

    Thanks a lot
    Schmidt for you help..

    possible combinations =32


    That's it

Posting Permissions

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



Click Here to Expand Forum to Full Width