PUBLIC arreglo AS NEW Integer[]
PUBLIC SUB Button1_Click()
DIM i AS Integer
'preparamos el arreglo para dividir el numero en cada uno de sus digitos
arreglo.Clear
'limpiamos la lista contenida en el control
ListBox1.Clear
'separamos el numero en cada uno de sus digitos y los colocamos en un arreglo
FOR i = 0 TO ValueBox1.Length - 1
ValueBox1.Select(i, 1)
arreglo.Add(ValueBox1.Selection.Text)
NEXT
'iniciamos la permutacion llamando a funcion
'permutar pasando como parametros la cantidad de digitos que contiene el numero
permutar(arreglo.Count)
END
'se aplica la recursividad para lograr la permutacion
PRIVATE SUB permutar(n AS Integer)
DIM i, j AS Integer
DIM cd AS String
IF n > 1 THEN
FOR i = 1 TO n
j = arreglo[i - 1]
arreglo[i - 1] = arreglo[n - 1]
arreglo[n - 1] = j
permutar(n - 1) 'aqui se ve la recursividad se llama asi misma la funcion
j = arreglo[i - 1]
arreglo[i - 1] = arreglo[n - 1]
arreglo[n - 1] = j
NEXT
ELSE
cd = arreglo[0]
FOR i = 1 TO arreglo.Count - 1
cd = cd & arreglo[i]
NEXT
ListBox1.Add(cd)
ENDIF
END