anupamduttabesu
New Member
- Joined
- Mar 24, 2013
- Messages
- 5
Hi
I have multiple text file where under ZEBI command datas are in the format...the datas under the command ZEBI ends with "COMMAND EXECUTED ".
< ZEBI;
LOADING PROGRAM VERSION 21.15-0
EXECUTION STARTED
BSC3i BSC1000 2012-04-10 11:23:49
MOBILE ALLOCATION FREQUENCY LIST - 1 BAND ... 1800
FREQUENCIES:
874 875 876 877 878 879 880 881
ATTACHED AS MOBILE ALLOCATION FREQUENCY LIST TO BTS:
549 KOL51731 619 KOL51732 620 KOL51733
1124 KOL49141
MOBILE ALLOCATION FREQUENCY LIST - 2 BAND ... 1800
FREQUENCIES:
802 803 804 805
COMMAND EXECUTED
Now i need the data in excel format as below.....
[TABLE="width: 695"]
<TBODY>[TR]
[TD]MOBILE ALLOCATION FREQUENCY LIST</SPAN>[/TD]
[TD]BAND</SPAN>[/TD]
[TD]FREQUENCIES</SPAN>[/TD]
[/TR]
[TR]
[TD="align: right"]1</SPAN>[/TD]
[TD="align: right"]1800 </SPAN>[/TD]
[TD]874 875 876 877 878 879 880 881 </SPAN>[/TD]
[/TR]
[TR]
[TD="align: right"]2</SPAN>[/TD]
[TD="align: right"]1800 </SPAN>[/TD]
[TD] 802 803 804 805 </SPAN>[/TD]
[/TR]
</TBODY><COLGROUP><COL><COL><COL></COLGROUP>[/TABLE]
Here From the text line
"MOBILE ALLOCATION FREQUENCY LIST - 1 BAND ... 1800"
We take data 1 and 1800 and put in the excel under the header MOBILE ALLOCATION FREQUENCY LIST AND BAND.
And fron the two lines
"FREQUENCIES:
874 875 876 877 878 879 880 881"
we take data "874 875 876 877 878 879 880 881" under the header FREQUENCY.
Please help how to write the macro for that.
I have made a code to write the macro,but i am not abale to take the data from the next line of "FREQUENCY".
Here is the code..
Dim sFileName As Variant
Dim iFileNum As Integer
Dim sBuf As String
Dim bolRecordAdding As Boolean
Dim aryData As Variant
Dim aryOutput As Variant
ReDim aryData(1 To 4, 0 To 0)
sFileName = Application.GetOpenFilename(",*.txt", , , , True)
For a = LBound(sFileName) To UBound(sFileName)
iFileNum = FreeFile()
Open sFileName(a) For Input As iFileNum
Do While Not EOF(iFileNum)
Line Input #iFileNum, sBuf
If Not InStr(sBuf, "ZEBI") = 0 Then
Do While Not sBuf = "FREQUENCIES: "
Line Input #iFileNum, sBuf
If sBuf Like "*BSC*" Then
If Not InStr(1, sBuf, " ") = 0 Then
abcd = Trim(Mid(sBuf, InStr(1, sBuf, " ") + 1, (InStr(12, sBuf, " ")) - (InStr(1, sBuf, " "))))
End If
End If
Loop
Do While Not sBuf = "COMMAND EXECUTED"
Line Input #iFileNum, sBuf
If sBuf Like "MOBILE ALLOCATION FREQUENCY LIST*" Then
If Not InStr(1, sBuf, "-") = 0 Then
ReDim Preserve aryData(1 To 4, 1 To UBound(aryData, 2) + 1)
aryData(1, UBound(aryData, 2)) = abcd
aryData(2, UBound(aryData, 2)) = Trim(Mid(sBuf, 37, 10))
aryData(3, UBound(aryData, 2)) = Trim(Mid(sBuf, 55, 10))
bolRecordAdding = True
End If
ElseIf sBuf Like "FREQUENCIES:*" Then
If Not InStr(1, sBuf, ":") = 0 _
And bolRecordAdding Then
aryData(4, UBound(aryData, 2)) = here what to write to take data from next line of frequency
bolRecordAdding = False
End If
End If
Loop
End If
Loop
Close iFileNum
Next a
I have multiple text file where under ZEBI command datas are in the format...the datas under the command ZEBI ends with "COMMAND EXECUTED ".
< ZEBI;
LOADING PROGRAM VERSION 21.15-0
EXECUTION STARTED
BSC3i BSC1000 2012-04-10 11:23:49
MOBILE ALLOCATION FREQUENCY LIST - 1 BAND ... 1800
FREQUENCIES:
874 875 876 877 878 879 880 881
ATTACHED AS MOBILE ALLOCATION FREQUENCY LIST TO BTS:
549 KOL51731 619 KOL51732 620 KOL51733
1124 KOL49141
MOBILE ALLOCATION FREQUENCY LIST - 2 BAND ... 1800
FREQUENCIES:
802 803 804 805
COMMAND EXECUTED
Now i need the data in excel format as below.....
[TABLE="width: 695"]
<TBODY>[TR]
[TD]MOBILE ALLOCATION FREQUENCY LIST</SPAN>[/TD]
[TD]BAND</SPAN>[/TD]
[TD]FREQUENCIES</SPAN>[/TD]
[/TR]
[TR]
[TD="align: right"]1</SPAN>[/TD]
[TD="align: right"]1800 </SPAN>[/TD]
[TD]874 875 876 877 878 879 880 881 </SPAN>[/TD]
[/TR]
[TR]
[TD="align: right"]2</SPAN>[/TD]
[TD="align: right"]1800 </SPAN>[/TD]
[TD] 802 803 804 805 </SPAN>[/TD]
[/TR]
</TBODY><COLGROUP><COL><COL><COL></COLGROUP>[/TABLE]
Here From the text line
"MOBILE ALLOCATION FREQUENCY LIST - 1 BAND ... 1800"
We take data 1 and 1800 and put in the excel under the header MOBILE ALLOCATION FREQUENCY LIST AND BAND.
And fron the two lines
"FREQUENCIES:
874 875 876 877 878 879 880 881"
we take data "874 875 876 877 878 879 880 881" under the header FREQUENCY.
Please help how to write the macro for that.
I have made a code to write the macro,but i am not abale to take the data from the next line of "FREQUENCY".
Here is the code..
Dim sFileName As Variant
Dim iFileNum As Integer
Dim sBuf As String
Dim bolRecordAdding As Boolean
Dim aryData As Variant
Dim aryOutput As Variant
ReDim aryData(1 To 4, 0 To 0)
sFileName = Application.GetOpenFilename(",*.txt", , , , True)
For a = LBound(sFileName) To UBound(sFileName)
iFileNum = FreeFile()
Open sFileName(a) For Input As iFileNum
Do While Not EOF(iFileNum)
Line Input #iFileNum, sBuf
If Not InStr(sBuf, "ZEBI") = 0 Then
Do While Not sBuf = "FREQUENCIES: "
Line Input #iFileNum, sBuf
If sBuf Like "*BSC*" Then
If Not InStr(1, sBuf, " ") = 0 Then
abcd = Trim(Mid(sBuf, InStr(1, sBuf, " ") + 1, (InStr(12, sBuf, " ")) - (InStr(1, sBuf, " "))))
End If
End If
Loop
Do While Not sBuf = "COMMAND EXECUTED"
Line Input #iFileNum, sBuf
If sBuf Like "MOBILE ALLOCATION FREQUENCY LIST*" Then
If Not InStr(1, sBuf, "-") = 0 Then
ReDim Preserve aryData(1 To 4, 1 To UBound(aryData, 2) + 1)
aryData(1, UBound(aryData, 2)) = abcd
aryData(2, UBound(aryData, 2)) = Trim(Mid(sBuf, 37, 10))
aryData(3, UBound(aryData, 2)) = Trim(Mid(sBuf, 55, 10))
bolRecordAdding = True
End If
ElseIf sBuf Like "FREQUENCIES:*" Then
If Not InStr(1, sBuf, ":") = 0 _
And bolRecordAdding Then
aryData(4, UBound(aryData, 2)) = here what to write to take data from next line of frequency
bolRecordAdding = False
End If
End If
Loop
End If
Loop
Close iFileNum
Next a