-
Sep 18th, 2014, 02:34 PM
#1
Thread Starter
New Member
[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.
-
Sep 18th, 2014, 02:44 PM
#2
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.
-
Sep 18th, 2014, 02:52 PM
#3
Thread Starter
New Member
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.
-
Sep 18th, 2014, 03:46 PM
#4
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
-
Sep 18th, 2014, 04:37 PM
#5
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
-
Sep 18th, 2014, 04:46 PM
#6
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|