473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Number Combination

I have a Table (Table01)in Access with one number field name Num (double)
I want a routine to create a new table ex.Table02 with 2 fields the first
with combinations and the 2nd with the sum of the combinations

Example:

Table01
NUM
1
2
3

Table02
Field01 Field02
1 1
2 2
3 3
1,2 3
1,3 4
2,3 5
1,2,3 6

Thanks,
Sotiris
Aug 27 '07 #1
3 1265
kadghar
1,295 Expert 1GB
It seems interesting.
i'll give it a try with arrays: lets say your table is called Table1 and is a doubles array. and lets make Table2 an strings one 'cause we are writing numbers and commas:

Expand|Select|Wrap|Line Numbers
  1. Dim Table2() As String
  2. Dim TmpDou As Double
  3. Dim i() As Integer 'hoping you table has less than 32000 elements
  4. Dim j As Integer
  5. Dim n As Integer
  6. Dim k As Long 'this will be for counting the combinations
  7. Dim Boo1 As Boolean
  8. TmpDou = UBound(Table1) - LBound(Table1) + 1 'The number of elements in table1
  9. TmpDou = 2 ^ TmpDou - 1  'the number of combinations excluding the empty one
  10. ReDim Table2(1 To TmpDou, 1 To 2) 'this will be our working space
  11. ReDim i(1 To TmpDou)  'this will be for counting
  12. 'In case your indexes doesnt start at cero:
  13.  
  14. n = 1
  15. Do
  16.     If n > UBound(Table1) - LBound(Table1) + 1 Then Exit Do
  17.     ReDim i(1 To n)
  18.     For j = 0 To n - 1
  19.         i(j + 1) = LBound(Table1) + j
  20.     Next
  21.     Do
  22.         k = k + 1
  23.         TmpDou = 0
  24.         For j = 1 To n
  25.             Table2(k, 1) = Table2(k, 1) & Table1(i(j)) & ", "
  26.             TmpDou = TmpDou + Table1(i(j))
  27.         Next
  28.         Table2(k, 1) = Left(Table2(k, 1), Len(Table2(k, 1)) - 2)
  29.         Table2(k, 2) = TmpDou
  30.         i(n) = i(n) + 1
  31.         If i(n) > UBound(Table1) Then
  32.             j = n - 1
  33.             i(n) = UBound(Table1)
  34.             Do
  35.                 If j = 0 Then
  36.                     Boo1 = True
  37.                     Exit Do
  38.                 End If
  39.                 If i(j) < i(j + 1) - 1 Then
  40.                     i(j) = i(j) + 1
  41.                     i(j + 1) = i(j) + 1
  42.                     Exit Do
  43.                 Else
  44.                     j = j - 1
  45.                 End If
  46.             Loop
  47.         End If
  48.         If Boo1 = True Then
  49.             n = n + 1
  50.             Boo1 = False
  51.             Exit Do
  52.         End If
  53.  
  54.     Loop
  55. Loop
I think there's an easier way, but this one works
Aug 28 '07 #2
Thank you for the reply,
is that possible to create this code in Access database (mdb) file,
with one table with the number for combinations, 2nd table with the
results and a form with the button than will run the code.

Thans Sotiris
Sep 2 '07 #3
kadghar
1,295 Expert 1GB
Thank you for the reply,
is that possible to create this code in Access database (mdb) file,
with one table with the number for combinations, 2nd table with the
results and a form with the button than will run the code.

Thans Sotiris
Yeap, its possible, what you need is to transform the arrays into mdb files.
That's a questin that has already been asked here: http://www.thescripts.com/forum/thread553126.html so i think that might be of help.

Just transform the data base into an array, use the code i gave you, and create the answer array, then transform it into an mdb... I think there should be other ways, but this one could be of help.
Sep 3 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: tom | last post by:
Hi, How do I get the serial number of the harddisk in .NET? I want this to be the same number even if the user has reformatted, so I do not want the volume serial number. Thanx, t
8
by: King | last post by:
Hi I have following MS Acess query Here is the query ID Name Prgm ID Client ID Date Start Time End Time Minutes C4 Trisha TIP DEK0703 7 /7 /2006...
109
by: jmcgill | last post by:
Hello. Is there a method for computing the number of digits, in a given numeric base, of N factorial, without actually computing the factorial? For example, 8! has 5 digits in base 10; 10! has...
22
by: MLH | last post by:
If 3 things can be in one of 2 states, the number of possible combinations is equal to 2^3. But if I have 3 things, 2 of which can be in 2 states and the other in 3 states, what's the simplest...
1
by: alex28011969 | last post by:
hi there, i'm a newby in the world of XML but can somebody tell me how to create a tooltip in a XML document that contains a combination of a name & number? i use a combination with Flash and...
0
barbk
by: barbk | last post by:
Hey all, In DB2 v9 is it possible to have an auto generated number field within a primary key that is a combination of multiple fields? For example resv locn sale_no 1234 789...
10
by: csfong33 | last post by:
Hi, I have arrays below: arr1 = { a, b, c} arr2 = {1, 2, 3} arr3 = {x, y, z} I want to get a combination of these array, as below arr_result = { "a1x", "a1y", "a1z", "a2x", "a2y", "a2z",...
5
by: Bails | last post by:
Hi all I have a theory for a lotto system and need help on how to code it. I want to create 1 massive database with EVERY combination of numbers possible in a given lotto system, then remove all...
8
by: theCancerus | last post by:
Hi All, I am not sure if this is the right place to ask this question but i am very sure you may have faced this problem, i have already found some post related to this but not the answer i am...
1
jinalpatel
by: jinalpatel | last post by:
I am dealing with 3 tables. Here is a brief meta data see the attachment for the relationship Conditions: 1)One GrantIndex can have multiple Deliverables 2)one Deliverable is made from...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.