|
↑Try2()を提示のLogファイルサンプルに対して実行すると、
イミディエイト・ウィンドウには
----------------------
hostname ABC
2000
220-221
306
2105-2107
3100-3103
----------------------
と表示されると思います。
↓を走らせると、
Sub Try3()
Dim io As Integer
Dim myLogFile As String: myLogFile = "E:\(Data)\temp8Log\hoge.log"
Dim buf() As Byte
Dim ss() As String, s As String, Series, num As Long
Dim hostname As String, ok As Boolean
Dim i As Long, j As Long
Dim rex As RegExp
Dim mm As Match
Set rex = New RegExp
io = FreeFile()
Open myLogFile For Binary As io
ReDim buf(1 To LOF(io))
Get io, , buf
Close io
ss = Split(StrConv(buf, vbUnicode), vbCrLf)
With rex
.Pattern = "[\d-]+"
.Global = True
For i = 0 To UBound(ss) - 1
If Not ok Then
If ss(i) Like "hostname*" Then
hostname = Split(ss(i))(1)
Debug.Print "hostname", hostname
ok = True
End If
ElseIf ss(i) Like "vlan*" Then
For Each mm In .Execute(ss(i))
s = mm.Value
If s <> "-" Then
Series = Split(s, "-")
num = Series(0)
For j = num To Val(Series(UBound(Series)))
Debug.Print j;
Next
Debug.Print
End If
Next
End If
Next
End With
End Sub
こんどはイミディエイト・ウィンドウに
----------------------
hostname ABC
2000
220 221
306
2105 2106 2107
3100 3101 3102 3103
----------------------
と表示されると思います。
#こんな風に、すこしづつ仕様に近づけていってください。
|
|