Hi guys. Im a student and i have a problem in finding the right procedure to solve my problem. Giving a set of numbers that will find their combination for a given value. For example 1st digit will be the size and the 2nd digit will be the qty.:

Size qty
10 10
20 10
30 10
40 10
50 10
60 10
70 10
80 10
90 10
100 10

the problem will be, I’ll find the 1 to 5 combinations to have a sum of 100:
the answers will be like the following:

100 10
90+10 10
80+20 10
70+30 10
40+60 10
50+50 5

the answers is only 1 and 2 combinations. I would like to create a procedure that will compute up to 5 combinations and will check the qty is still available for combining into another size. the problem is my function becomes very slow when im trying to manipulate it using string handling functions. Any input that will enlighten my mind will be a great help. Thanks in advance.

Please specify the total number of sequence (ex.. 1 to totalnumberofsequence) if the total number of sequence is base on the input try this systax

Dim input as integer
dim algo as integer
dim cnt as integer
dim combo as integer

'no of sequence
algo = 0
for cnt = 1 to input
algo = algo + input
? algo, input
next cnt

'finding the combination
cnt = 0
combo = algo
algo = algo - input
while combo = algo
cnt = cnt + 1
combo = (algo + input)
input = input + input


' cnt is the total number of combination

thanks for the input locsin. i already created a function that will loop (1 to 5 comb) to combine the given set of numbers. the problem is im having trouble with getting the difference of the qty. for example:

combination requirement= 400

size 100+90+80+70+60

qty respectively 10,9,8,7,6


6 set for 100+90+80+70+60

qty respectively 4,3,2,1,0


this sample is easy to compute coz of theres no redundant size have been combined. the next example will be a little bit of complicated:

combination requirement= 400

size 100+100+90+80+30

qty respectively 10,10,11,12,13


5 sets for 100+100+90+80+30

qty respectively 0,0,6,7,8

the problem is, am having trouble with getting the difference of the qty. for now, im using a string handling function for computation of combinations but reducing the qty is my main problem using that function( ex. sorting the qty and determining the lowest qty to be the set size). can someone suggest an idea that will help me to solve my problem? thanks all.

btw, im using a two dimensional array to manipulate my string. is there any function in vb that i can store my var and automaticaly sort them?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.