使用Mid命令

时间:2016-01-08 17:36:28

标签: vba excel-vba excel

我有以下原始文件和代码。但输出结果如下所示。我想仅使用一些过滤条件打印第1行和第3行,如果 LAC 仅以 2 开头,则会打印。

RAW数据

BASE TRANSCEIVER STATION DATA

BTS   NAME :ZTELGEI5                     NUMBER  :2465
BSC   NAME :BSCDLF4                      NUMBER  :4
LA    NAME :LAC2195                      LAC     :2195
MOBILE COUNTRY CODE ....................(MCC)... :404  
MOBILE NETWORK CODE ....................(MNC)... :31   
CELL IDENTITY ..........................(CI).... :2465
BTS ADMINISTRATIVE STATE ....................... :UNLOCKED

ROUTING ZONE ...........................(RZ).... :173
NEIGHBOUR BTS LIST:
                    NO NEIGHBOURS


BASE TRANSCEIVER STATION DATA

BTS   NAME :EKOLAGPR1                    NUMBER  :3011
BSC   NAME :BSC61DLM                     NUMBER  :830
LA    NAME :BSC61DLF                     LAC     :7043
MOBILE COUNTRY CODE ....................(MCC)... :404  
MOBILE NETWORK CODE ....................(MNC)... :31   
CELL IDENTITY ..........................(CI).... :3011
BTS ADMINISTRATIVE STATE ....................... :UNLOCKED

ROUTING ZONE ...........................(RZ).... :153           

NEIGHBOUR BTS LIST:
                    NO NEIGHBOURS

BASE TRANSCEIVER STATION DATA

BTS   NAME :ZTACMI2                      NUMBER  :322942
BSC   NAME :BSC6ALI1                     NUMBER  :106
LA    NAME :LAC2170                      LAC     :2170
MOBILE COUNTRY CODE ....................(MCC)... :404  
MOBILE NETWORK CODE ....................(MNC)... :31   
CELL IDENTITY ..........................(CI).... :22942
BTS ADMINISTRATIVE STATE ....................... :UNLOCKED

ROUTING ZONE ...........................(RZ).... :144          

NEIGHBOUR BTS LIST:
                    NO NEIGHBOURS

代码

If Left(Str, 12) = "BTS   NAME :" Then
    BTS_Name = Mid(Str, 13, 10)
End If
If Left(Str, 12) = "BTS   NAME :" Then
    BTS_NUMBER = Mid(Str, 51, 10)
End If
If Left(Str, 12) = "LA    NAME :" Then
    LAC = Mid(Str, 51, 4)
End If
If Left(Str, 50) = "CELL IDENTITY ..........................(CI).... :" Then
    CELL_ID = Mid(Str, 51, 10)
End If
If Left(Str, 50) = "BTS ADMINISTRATIVE STATE ....................... :" Then
    BTS_STATUS = Mid(Str, 51, 10)
End If
If Left(Str, 50) = "ROUTING ZONE ...........................(RZ).... :" Then
    RZ = Mid(Str, 51, 10)

    SL_NO = SL_NO + 1
    str1 = CStr(SL_NO) + "," + CELL_ID + "," + LAC + "," + BTS_Name + "," + BTS_NUMBER + "," + BTS_STATUS + "," + RZ
    Print #1, str1
End If

输出

enter image description here

https://drive.google.com/file/d/0B1cIJpdD9uvza3ZpMnNlT0cyb2M/view?usp=sharing

1 个答案:

答案 0 :(得分:1)

If LAC Like "2*" Then

    str1 = CStr(SL_NO) & "," & CELL_ID & "," & LAC + "," & BTS_Name & "," & _
                         BTS_NUMBER & "," & BTS_STATUS & "," & RZ
    Print #1, str1

End If