# numbers combinations

Hi guys

i have 5 numbers as follow: 1,2,3,4,5

i need to make all possible combinations between them like this:

1-2
1-3
1-4
1-5
2-3
2-4
2-5
3-4
3-5
4-5
an display the result into a listbox

Do you have any idea on how to do that?

Thanks guy

``````n=5
for i=1 to n-1
for j=i+1 to n
'i and j are your two numbers
next
next``````

HI Robert

Pretty Cool

Thanks

Hi

Robert solution work fine, but i have the next question:

If i want to combine this numbers sequence as follow : 43-45-78-90-21 into

43-45
43-78
43-90
43-91
45-78
45-90
45-21
78-90
78-21
90-21

i believe that Robert solution will not work.

Any suggestion?

Thanks

``````dim v() as string
dim i as integer
dim j as integer
v=split(string_of_number,"-")
for i=0 to v.ubound-1
for j=i+1 to v.ubound
//  v(i) and v(j) are your two numbers (as string values)
next j
next i``````

Thanks Dave

Very nice solution

Thans

Hi Dave

[b]dim v() as string
dim i as integer
dim j as integer

v=split(txtUno.Text,"-")

for i=0 to v.ubound-1
for j=i+1 to v.ubound

``````  Listbox1.AddRow str(i) +"-" str(j))

//  v(i) and v(j) are your two numbers (as string values)
next j
``````

next i[/b]

but the result is not what im aspecting

if i put this sequence if numbers onto txtUno.text 33-44-55-66-77

im getting this as in the picture:

From where is getting different numbers of the combination

Thanks

Instead of making code bold, use the `[code]` tags to format it
Your picture didn’t come through, what kind of output are you getting?

plus
NOT

``Listbox1.AddRow str(i) +"-" + str(j)``

but

``Listbox1.AddRow v(i) +"-" + v(j)``

Ok Guys

Thanks for the tips

I think you also need another + after the “-”

``Listbox1.AddRow v(i) +"-"+ str(j))``

And it should be

``Listbox1.AddRow v(i) +"-"+ v(j)``

Thanks Wayne, Dave and Tim

It works fine now

I didn’t help at all, but you’re welcome
(I tried, but joined the thread late)

Tim

you help me on how to use better the forum tools… so thanks!

When I have some free time later I’ll put together a video covering the basics.

Edit: I was informed that there is actually a post about it https://forum.xojo.com/8761-post-formatting-and-tips

Hi Tim