-2

I have multiple VB6 .frm files. See example below. I want to strip away the functions and subs from the code and leave only the form design.

What I need to do is find the last line starting with "Attribute" because after this line everything further should be deleted.

Using pattern matching or something similar, how can I process the .frm files so that everything after the last Attribute line is deleted? If I am traversing through a file, how can I tell where the last Attribute line is?

Example of .frm file:

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 
CJ7
  • 22,579
  • 65
  • 193
  • 321
  • Show us the essential code you already wrote to traverse the file, and the community will tell you what you have to add to do what you want to. And tell us what language you are using to traverse the files - C# I guess? – Doc Brown Nov 21 '11 at 07:02
  • 1
    Same as your [previous question](http://stackoverflow.com/questions/8206848/how-to-remove-all-code-from-multiple-vb6-frm-files-and-leave-form-design). Please only ask once for the same question. – Deanna Nov 21 '11 at 09:28

1 Answers1

0

You just need 2 rules:

1) If line starts with 'Attribute' then don't delete. 2) If line starts with 'Attribute' set a flag to start deleting all subsequent lines.

Rule #1 will prevent you from deleting subsequent Attribute lines, and there should be nothing you want to keep after the first Attribute you encounter unless it's an Attribute.

Brandon Moore
  • 8,590
  • 15
  • 65
  • 120