-2

我有多个 VB6.frm文件。请参见下面的示例。我想从代码中去掉函数和子代码,只留下表单设计。

我需要做的是找到以“属性”开头的最后一行,因为在此行之后应该删除所有进一步的内容。

使用模式匹配或类似的东西,如何处理.frm文件以便删除最后一个 Attribute 行之后的所有内容?如果我正在遍历一个文件,我如何知道最后一个 Attribute 行在哪里?

文件示例.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 
4

1 回答 1

0

你只需要两条规则:

1)如果行以“属性”开头,则不要删除。2)如果行以“属性”开头,则设置一个标志以开始删除所有后续行。

规则 #1 将阻止您删除后续的属性行,并且在您遇到的第一个属性之后应该没有任何内容要保留,除非它是一个属性。

于 2011-11-21T06:45:36.307 回答