Help with Macro

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Guest

Help with Macro

Post by Guest »

Hi,

this may be easy but I am new to Textpad. I have a data file that is structured header and multiple line records (variable number). This repeats thoughout the file. After the last line record is a summary line (denoted with a *). I would like to either add the header line to all of the details lines and stop at the summary line or just add a key column from the header line to each detail line. I can then use this in some other database program to join the data together. Could anyone suggest a way to do this using a Macro that I can repeat through the end of the file.

Many thanks.
User avatar
Bob Hansen
Posts: 1517
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Assume following layout:

header line
data1;col1;col2;col3;col4;col5
data2;col1;col2;col3;col4;col5
data3;col1;col2;col3;col4;col5
data4;col1;col2;col3;col4;col5
*summary

To add the header line to all of the details lines and stop at the summary line, try this:

Macro1 - Get Header info(run once)
CTL-HOME to top of file
Find Header string
Shift-End to highlight Header line
CTL-C to copy to clipboard
Call macro2 (use down arrows to select from Macros menu)

Macro2 - Add header to details (run to end)
Home, Down arrow, end to get to end of data line
Type in delimiter (;)
CTL-V to paste
Call Macro3 (use down arrows to select from Macros menu)

Macro3 - Clean last line (run once)
CTL-HOME to top of file
Find * to go to summary line
Find delimiter (;), to go to delimiter (;), close Find window
Shift-End to highlight to end of line
Delete
============================
After Macro2 you will have:
header line
data1;col1;col2;col3;col4;col5;header line
data2;col1;col2;col3;col4;col5;header line
data3;col1;col2;col3;col4;col5;header line
data4;col1;col2;col3;col4;col5;header line
*summary;header line

After Macro3 you will have:
header line
data1;col1;col2;col3;col4;col5;header line
data2;col1;col2;col3;col4;col5;header line
data3;col1;col2;col3;col4;col5;header line
data4;col1;col2;col3;col4;col5;header line
*summary
==============================
ALL DONE!
==============================
Hope this helps.

WARNING! Macros cannot be edited. Must be 100% accurate for all unexpected conditions. Example, selecting macros may mean moving the down arrow 5 times. but if you later add more macros to menu, 5 arrows may call the wrong one. Suggest naming macros with leading # so you can always arrange them in same order.

These macros will call other macros, so they must exist already.

Record Macro 3 first, and save it to list of macros on menu
Record Macro 2 next, and save it to list of macros on menu
Record Macro 1 finally, and save it to list of macros on menu

Instead of delimiter, you may have to go to column position if file is fixed length fields. You may also want to use a temporary delimiter for the macro (~), then mave macro4 do a search and replace for that delimiter when macro 3 is completed. You are the only one who can make these types of decisions, depends on the file layouts and variations you might expect to see.

Good luck......
Hope this was helpful.............good luck,
Bob
Post Reply