2011-11-21 25 views
-2

我有多個VB6 .frm文件。見下面的例子。我想剝離代碼中的函數和子集,只留下表單設計。模式匹配處理多個.frm文件

我需要做的是找到以「屬性」開頭的最後一行,因爲在此行之後,應該刪除所有內容。

使用模式匹配或類似的方法,我如何處理.frm文件,以便刪除最後一個屬性行後的所有內容?如果我遍歷一個文件,我怎麼知道最後一個屬性行是在哪裏?

.frm文件的示例:

VERSION 5.00 
Begin VB.Form Form1 
    Caption = "Form1" 
    ClientHeight = 3195 
    ClientLeft = 60 
    ClientTop = 345 
    ClientWidth = 4680 
    LinkTopic = "Form1" 
    ScaleHeight = 3195 
    ScaleWidth = 4680 
    StartUpPosition = 3 'Windows Default 
    Begin VB.CommandButton Command1 
     Caption = "Command1" 
     Height = 495 
     Left = 1800 
     TabIndex = 1 
     Top = 1320 
     Width = 1215 
    End 
    Begin VB.TextBox Text1 
     Height = 495 
     Left = 360 
     TabIndex = 0 
     Text = "Text1" 
     Top = 240 
     Width = 1215 
    End 
End 

Attribute VB_Name = "Form1" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = False 
Attribute VB_PredeclaredId = True 
Attribute VB_Exposed = False 

Private Sub Command1_Click() 
    Text1.Text = "Hello World" 
End Sub 
Private Sub Form_Load() 
    Text1.BackColor = vbBlue 
End 
+0

向我們展示您已經編寫的遍歷文件的基本代碼,社區會告訴您必須添加什麼來執行您想要的操作。並告訴我們你用什麼語言來遍歷文件 - 我猜是C? –

+1

與您的[上一個問題]相同(http://stackoverflow.com/questions/8206848/how-to-remove-all-code-from-multiple-vb6-frm-files-and-leave-form-design)。請只問一次相同的問題。 – Deanna

回答

0

你只需要2個規則:

1)如果符合 '屬性',那麼不要刪除開始。 2)如果行以'Attribute'開頭,則設置一個標誌以開始刪除所有後續行。

規則1將阻止您刪除後續的屬性行,並且在遇到第一個屬性後應該保留任何內容,除非它是屬性。