exllearner
New Member
plz provide good example when text file open in vb to processed
Option Explicit
Sub X()
Dim MyString, MyNumber
Dim I, J, K, S As String
Dim file As Variant
Dim A, B, C As Boolean
file = Application.GetOpenFilename("", 0, "Select ZEEI Log file", "", 0)
Open file For Input As #1
Sheets("ZEEI").Select
Cells.Clear
With Application
.Calculation = xlManual
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False
Cells(1, 1) = "BCF ID"
Cells(1, 2) = "TYPE"
Cells(1, 3) = "LAC"
Cells(1, 4) = "CI"
Cells(1, 5) = "BTS ID"
Cells(1, 6) = "SEG NAME"
Cells(1, 7) = "HOP"
Cells(1, 8) = "TRX"
Cells(1, 9) = "FREQ"
Cells(1, 10) = "ET-PCM"
Cells(1, 11) = "BCCH/CBCH"
Cells(1, 12) = "PREF"
Cells(1, 13) = "ADMIN STATE"
Cells(1, 14) = "OPER. STATE"
I = 2
A = False
B = False
C = False
Do While Not EOF(1)
On Error GoTo P
Line Input #1, S
If (InStr(S, "BCF-") <> 0) Then
A = True
Cells(I, 1) = Trim(Mid(S, 5, 4))
Cells(I, 2) = Trim(Mid(S, 11, 10))
End If
If (InStr(S, "BTS-") <> 0) Then
B = True
Cells(I, 3) = Trim(Mid(S, 1, 6))
Cells(I, 4) = Trim(Mid(S, 8, 5))
Cells(I, 5) = Trim(Mid(S, InStr(S, "BTS-") + 4, 4))
Line Input #1, S
Cells(I, 6) = Trim(Mid(S, 1, 15))
Cells(I, 7) = Trim(Mid(S, 19, 2))
End If
If (InStr(S, "TRX-") <> 0) Then
C = True
Cells(I, 8) = Trim(Mid(S, 19, 3))
Cells(I, 9) = Trim(Mid(S, 34, 5))
Cells(I, 10) = Trim(Mid(S, 42, 4))
Cells(I, 11) = Trim(Mid(S, 47, 10))
Cells(I, 12) = Trim(Mid(S, 61, 1))
Cells(I, 13) = Trim(Mid(S, 24, 1))
Cells(I, 14) = Trim(Mid(S, 26, 6))
End If
If (C = True) Then
I = I + 1
A = False
B = False
C = False
End If
Loop
Close #1
Application.Calculation = xlCalculationAutomatic
GoTo Q
P:
' and now what?
Q:
End Sub
-----
I get a result output as this, which is different than what you posted:
-----
BCF ID TYPE LAC CI BTS ID SEG NAME HOP TRX FREQ ET-PCM BCCH/CBCH PREF ADMIN STATE OPER. STATE
1 LEXI EDGE 950 3531 1 VASANTKUNMR1 RF 12 P 5 M CCH+CB
12 5
12 5
12 0
950 3532 2 VASANTKUNMR2 RF 12 P 5 M CCH+CB
12 P 3
12 3
950 3533 3 VASANTKUNMR3 RF 19 3
12 P 4 M CCH+CB
12 4