Option
Explicit
Public
Sub
test()
Const
C_TAB1
As
Integer
= 50
Dim
pdf()
As
Variant
Dim
nr()
As
Variant
pdf = Array(
"Betrieb_Henkel_7341625.pdf"
, _
"Betrieb_Telekom_1562347.pdf"
, _
"Betrieb_Handknecht_1234567.pdf"
, _
"Betrieb_Infineon_1732645.pdf"
, _
"Betrieb_Firmenname_1475623.pdf"
, _
"Betrieb_AMD_3261754.pdf"
, _
"Betrieb_Bayer_5623417.pdf"
, _
"Betrieb_Siemens_4521736.pdf"
, _
"Betrieb_MöbeltransportUnger_4152736.pdf"
)
ReDim
nr(LBound(pdf)
To
UBound(pdf))
Dim
s
As
Long
, e
As
Long
Dim
i
As
Long
For
i = LBound(nr)
To
UBound(nr)
s = InStrRev(pdf(i),
"_"
)
e = InStrRev(pdf(i),
"."
)
If
e > s
And
s > 0
Then
nr(i) = Mid$(pdf(i), s + 1, e - s - 1)
Else
Call
Err.Raise(vbObjectError + 1,
"test()"
,
"Konnte Nummer in Dateinamen nicht finden"
)
End
If
Next
Dim
idx()
As
Long
Call
bubbleSort(nr, idx)
Debug.Print
Debug.Print
"PDF"
; Tab(C_TAB1);
"NR(sortiert)"
For
i = LBound(pdf)
To
UBound(pdf)
Debug.Print
"'"
& pdf(idx(i)) &
"'"
; Tab(C_TAB1); nr(idx(i))
Next
Call
MsgBox(
"Fertig."
, vbInformation)
Erase
idx, nr, pdf
End
Sub
Public
Sub
bubbleSort(val()
As
Variant
,
ByRef
idx()
As
Long
)
Dim
t
As
Variant
Dim
i
As
Long
Dim
j
As
Long
ReDim
idx(LBound(val)
To
UBound(val))
For
i = LBound(idx)
To
UBound(idx)
idx(i) = i
Next
For
i = UBound(val) - 1
To
LBound(val)
Step
-1
For
j = i
To
UBound(val) - 1
If
val(idx(j)) > val(idx(j + 1))
Then
t = idx(j)
idx(j) = idx(j + 1)
idx(j + 1) = t
End
If
Next
Next
End
Sub