Option
Explicit
Private
Type TVersion
Major
As
Integer
Minor
As
Integer
End
Type
Public
Sub
Test()
Dim
regExp
As
Object
:
Set
regExp = CreateObject(
"VBScript.RegExp"
)
Dim
regExpM
As
Object
Dim
udtRepoV
As
TVersion
Dim
udtWkbV
As
TVersion: udtWkbV = CVersionUDT(1, 0)
Dim
strRepoPath
As
String
: strRepoPath = "X:\Repo\"
Dim
strFolder
As
String
regExp.Pattern =
"(\d+)\.(\d+)"
strFolder = Dir$(strRepoPath, vbDirectory)
Do
Until
strFolder =
""
If
strFolder <>
"."
And
strFolder <>
".."
Then
Set
regExpM = regExp.Execute(strFolder)
If
regExpM.Count > 0
Then
If
CompareVersion(udtRepoV, CVersionUDT(
CInt
(regExpM(0).SubMatches(0)),
CInt
(regExpM(0).SubMatches(1)))) < 0
Then
udtRepoV.Major =
CInt
(regExpM(0).SubMatches(0))
udtRepoV.Minor =
CInt
(regExpM(0).SubMatches(1))
End
If
End
If
End
If
strFolder = Dir$()
Loop
Debug.Print
"höchste vorhandene Version"
; Tab(30); CVersionUDT2Str(udtRepoV)
Debug.Print
"Version der Mappe"
; Tab(30); CVersionUDT2Str(udtWkbV)
Select
Case
CompareVersion(udtWkbV, udtRepoV)
Case
0:
Call
MsgBox(
"Version der Mappe ist aktuell."
, vbInformation)
Case
-1:
Call
MsgBox(
"Version der Mappe ("
& CVersionUDT2Str(udtWkbV) &
") ist veraltet."
, vbExclamation)
Case
1:
Call
MsgBox(
"Version der Mappe ("
& CVersionUDT2Str(udtWkbV) &
") ist größer als Version im Repository."
& vbNewLine & vbNewLine &
"Bitte kontaktieren sie: 'Max Mustermann@diefirma.de'"
, vbCritical)
End
Select
Set
regExpM =
Nothing
Set
regExp =
Nothing
End
Sub
Private
Function
CVersionUDT(Major
As
Integer
, Minor
As
Integer
)
As
TVersion
CVersionUDT.Major = Major
CVersionUDT.Minor = Minor
End
Function
Private
Function
CVersionUDT2Str(Version
As
TVersion)
As
String
CVersionUDT2Str = Version.Major &
"."
& Version.Minor
End
Function
Private
Function
CompareVersion(Version
As
TVersion, VersionRef
As
TVersion)
As
Long
If
Version.Major = VersionRef.Major
And
Version.Minor = VersionRef.Minor
Then
CompareVersion = 0
ElseIf
Version.Major > VersionRef.Major
Then
CompareVersion = 1
Else
CompareVersion = -1
End
If
End
Function