Makro optimieren
28.05.2008 11:07:00
alifa
habe mir ein Macro für Permutationen gebastelt, doch irgendwie werden Werte von vorherigen Anwendungen übernommen und ausgewiesen. Wie werde ich die los? Gruß, alifa
Option Explicit
' Beispiel : Rekursive Permutation.
Dim strPermutation As String
Dim strZeichen As String
Dim intArray_Pos() As Integer
Dim intArray_Pos_Zeiger As Integer
Dim strErgebnis() As String
Dim lngCount As Long
Sub Uebergab() 'Fehler!!
Dim Kombination As String, i&, z%
Kombination = "12345"
Cells.ClearContents
Call Rekursive_Permutation(Kombination)
For i = 1 To lngCount
Cells(z + 1, 1) = strErgebnis(i)
z = z + 1
Next
End Sub
Sub Rekursive_Permutation(strUebergabe As String)
strZeichen = strUebergabe
intArray_Pos_Zeiger = -1
ReDim intArray_Pos(Len(strZeichen) - 1)
Call Permutation(0)
End Sub
Private Sub Permutation(intX As Integer)
Dim i As Integer
intArray_Pos_Zeiger = intArray_Pos_Zeiger + 1
intArray_Pos(intX) = intArray_Pos_Zeiger
If intArray_Pos_Zeiger = Len(strZeichen) Then
strPermutation = ""
For i = 0 To UBound(intArray_Pos)
strPermutation = strPermutation & _
Mid$(strZeichen, intArray_Pos(i), 1)
Next i
lngCount = lngCount + 1
ReDim Preserve strErgebnis(lngCount)
strErgebnis(lngCount) = strPermutation
Else
For i = 0 To Len(strZeichen) - 1
If intArray_Pos(i) = 0 Then Call Permutation(i)
Next i
End If
intArray_Pos_Zeiger = intArray_Pos_Zeiger - 1
intArray_Pos(intX) = 0
End Sub