How to insert a line at start and end of a procedure?

Help with writing and playing macros

How to insert a line at start and end of a procedure?

Postby kaipl » Wed Dec 06, 2006 6:08 pm

Hi there,

I do not get the trick for the following task. Maybe anyone could help me out? I got a file that looks like

Code: Select all
Private Function1(Param1, Param2)
  Some Code
  Some More Code
End Function

Private Function2(Param1, Param2)
  Some Code
  Some More Code
End Function


I'd like to add some text after the line Private Function... and some text befor the line End Function. so it look like that

Code: Select all
Private Function1(Param1, Param2)
  Trace("Function1")
  Some Code
  Some More Code
  EndTrace("Function1")
End Function

Private Function2(Param1, Param2)
  Trace("Function2")
  Some Code
  Some More Code
  EndTrace("Function2")
End Function


As you see, it would be great if the insertet text Trace("Function2") and EndTrace("Function1") hase the name of the function he is inserted to.

Some ideas? Many thanks in advance!
kai
User avatar
kaipl
Newbie
 
Posts: 1
Joined: Wed Dec 06, 2006 12:00 am

Re: How to insert a line at start and end of a procedure?

Postby Mofi » Thu Dec 07, 2006 7:33 am

This macro was created by simply recording a manual execution and then edited it a little (Loop, ExitLoop, ClearClipboard, ...). Maybe it's not perfect for you, but it works perfect for your example.

The macro property Continue if a Find with Replace not found must be checked for this macro.

InsertMode
ColumnModeOff
HexOff
Clipboard 9
Loop
Find MatchCase "Private"
IfNotFound
ExitLoop
EndIf
EndSelect
Key Ctrl+RIGHT ARROW
StartSelect
SelectWord
Copy
EndSelect
Key HOME
Key DOWN ARROW
" Trace(""
Paste
"")
"
Find MatchCase "End Function"
Key HOME
" EndTrace(""
Paste
"")
"
EndLoop
ClearClipboard
Clipboard 0
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4054
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros