Option
Explicit
Sub
Test()
Dim
strFileContent
As
String
Dim
FN
As
Integer
FN = FreeFile
Open
"X:\file.txt"
For
Input
As
#FN
strFileContent = Input(LOF(FN), #FN)
Close #FN
Dim
astrValues()
As
String
Dim
vntValue
As
Variant
astrValues = Split(GetValue(
"Windenergieanlage"
, strFileContent),
","
)
Debug.Print
"[Windenergieanlage]"
If
UBound(astrValues) >= 0
Then
For
Each
vntValue
In
astrValues
Debug.Print
" * "
& Trim$(vntValue)
Next
Else
Debug.Print
" ! nicht gefunden"
End
If
astrValues = Split(GetValue(
"Getriebe"
, strFileContent),
","
)
Debug.Print
"[Getriebe]"
If
UBound(astrValues) >= 0
Then
For
Each
vntValue
In
astrValues
Debug.Print
" * "
& Trim$(vntValue)
Next
Else
Debug.Print
" ! nicht gefunden"
End
If
End
Sub
Private
Function
GetValue(Key
As
String
, Expression
As
String
)
As
String
Dim
s
As
Long
Dim
e
As
Long
s = InStr(1, Expression, Key &
":"
, vbTextCompare)
If
s = 0
Then
Exit
Function
s = s + Len(Key) + 1
e = InStr(s, Expression, vbNewLine, vbBinaryCompare)
If
s = e
Then
If
e < Len(Expression)
Then
s = e + Len(vbNewLine)
e = InStr(s, Expression, vbNewLine, vbBinaryCompare)
Else
Exit
Function
End
If
End
If
GetValue = Mid$(Expression, s, e - s)
End
Function