copying irregular column data neatly between two other columns

2 views
Skip to first unread message

Larry

unread,
Nov 12, 2009, 8:40:17 PM11/12/09
to GoogleSemWare TSE, TsePro
(Okay, let's see if this is 'visible' :))

// copy irregular column between two irregular columns

<ctrlshift x><i> execmacro("jigirregcol")

/***
This macro will copy the text in a marked column to the position between
the irregular interior edges of two other columns.

Five assumptions:
1. that the marked column data has a one to one line relationship with the
target columns;
2. that the marked column be located to the left of the target columns;
3. that the cursor is at the top left column of the left target column;
4. that the left target column is left-justified;
5. that both target colums contain "words".

(Too many assumptions? :))

How to use:
1. mark the column to be copied;
2. place the cursor at the upper left corner of the left taget column;
3. execute this macro.

The result will be that the data from each line of the original marked
column will be placed between the two target columns and the separation
between the three columns will be one space.

Though use of this macro might be rare, one example might be to copy the
middle names between the first and last names, pulling them together
with only one space separations.

Other variations are possible. One might be to move a last name to its
proper column if it happened to be listed first.

One could also perform this method on "truly" jagged columns (that is,
no alignments) by copying the columns to temporary buffers and working
with them that way. This would also allow for missing words in the
target columns.

Example for the current macro: (if the formatting holds up in this email)

The columns:

Marked Target Target
Middle First Last
========== ==== ====

Magenta Black Brown
Purple Red Blue
Orange Yellow Gold

...become:

Magenta Black Magenta Brown
Purple Red Purple Blue
Orange Yellow Orange Gold

...after running this macro, even if the middle name is missing.

Once the middle names are copied, the original marked block can be
deleted...the macro does not delete it.

***/

proc main()

string a[255]=""

integer i=0
integer bl=query(blockbegline)
integer bc=query(blockbegcol)
integer el=query(blockendline)
integer ec=query(blockendcol)
integer cp=currpos()

if isblockmarked()==_column_
and iscursorinblock()==0
pushblock()
unmarkblock()
for i=bl to el
gotoline(i)
a=trim(gettext(bc,ec-bc+1))
gotopos(cp)
endword()
delrightword()
if a<>""
inserttext(" "+a+" ",_insert_)
endif
unmarkblock()
endfor
unmarkblock()
popblock()
gotoline(bl)
gotopos(cp)
scrolltocenter()
sound(9000,10)
message("jigirregcol Finished.")
else
sound(50,50)
warn("Either block not marked or cursor in block. Ending.")
endif

goto ending
ending:

end

Heijer, Rob den

unread,
Nov 13, 2009, 3:40:49 AM11/13/09
to sem...@googlegroups.com
Hi Larry,
It takes a while to see the usefulness of your macro. It behaves as promised, but I still think "why did you write this?" Anyway, here's an off-topic suggestion (for the whole gang!)

It might be nice to use tones of a scale, when a macro ends audibly.

a 440,00
466,16 =A1*2^(1/12)
b 493,88 =A2*2^(1/12)
c 523,25 and so on.
554,37
d 587,33
622,25
e 659,26
f 698,46
739,99
g 783,99
830,61
a 880,00

Round the frequencies to whole numbers. For a nice do-mi-so sound, try this:
sound(523,100)
sound(659,100)
sound(784,200)

Any volunteers for a piece of Mozart?
cheers,
Rob.

(Too many assumptions? :))

The columns:

...become:

***/

proc main()

string a[255]=""

goto ending
ending:

end


This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is
intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to
read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message
in error, please notify the sender immediately and delete all copies of this message.

Larry

unread,
Nov 13, 2009, 10:04:20 AM11/13/09
to sem...@googlegroups.com
Hi, Rob.

Well, I was doing some html stuff for a friend that involved a large number
of names to be displayed in several different ways on the pages of her
website. Manually manipulating these columns of names became a chore, so I
whipped up this and a couple of other jig macros to lighten the burden a
bit. :)

The manual way was to spread the two columns apart with spaces, then insert
the middle name column between then. It works, but requires several steps
and cleanup.

The macro as published doesn't 'quite' do what I said. I forgot to insert a
space where a middle name was supposed to be if there was no middle
name...the first and last name get stitched together, like, firstlast. No
good. I put the repair in the source in this reply.

I am still thinking about doing completely jagged columns (no alignment),
but haven't done it yet.

The next macro spreads the names (or other data, like comma-delimited dbs)
apart into neatly left-justified columns.

Uh, as for 'why', I guess it's a compulsion...I can't stop myself from
solving a problem I can't keep myself from thinking up! Squeezing an
irregular column neatly between two other irregular columns posed just that
kind of 'unfinished' problems I couldn't let go of.

I guess back in the 1950s, guys messed around with cars the same way. :)
Also, I always wondered why girls could play with paperdolls for hours
trying different combinations of clothes on Patti Page and Doris Day. Now I
guess I know. :)

--------------------------------------------------
From: "Heijer, Rob den" <rob.den...@capgemini.com>
Sent: Friday, November 13, 2009 2:40 AM
To: <sem...@googlegroups.com>
Subject: [TSE] Re: copying irregular column data neatly between two other
columns

// the repair start


if a<>""
inserttext(" "+a+" ",_insert_)

else
inserttext(" ",_insert_)
endif
// the repair ends

Carlo Hogeveen

unread,
Nov 15, 2009, 7:56:31 AM11/15/09
to sem...@googlegroups.com

Hi Rob,

I stumbled upon the macro below, and thought of your e-mail below.

Nozart

integer last_tune = 0

proc play_note(integer note)
string scale [255] =

"0100,0114,0128,0136,0150,170,0190,0200,0228,0256,0272,0300,0340,0380,0400"
integer duration = 4
if not KeyPressed()
case note
when 0
Delay(duration)
when 1 .. 15
Sound(Val(SubStr(scale, (note - 1) * 5 + 1, 4)),
duration * 1000 / 18)
endcase
endif
end

proc play_tune(string tune)
integer i = 0
for i = 1 to Length(tune)
play_note(Val(tune[i], 36))
endfor
end

proc sound_of_music()
play_tune("10023001301030002003443240000000")
play_tune("30045003503050004005665460000000")
play_tune("50012345600000006002345670000000")
play_tune("70034567800000876040705080503020")
end

proc Father_Jacob()
play_tune("8090a0808090a080a0b0c000a0b0c000")
play_tune("cdcba080cdcba0808050800080508000")
end

proc Yankee_Doodle()
play_tune("889a8a90")
play_tune("889a8050")
play_tune("889aba98")
play_tune("75678080")
play_tune("67656780")
play_tune("56543050")
play_tune("67656789")
play_tune("75678080")
end

proc do_music_part()
repeat
Delay(9)
if last_tune == 0
last_tune = (GetClockTicks() mod 3) + 1
endif
case last_tune
when 1
Sound_Of_Music()
last_tune = 2
when 2
Father_Jacob()
last_tune = 3
when 3
Yankee_Doodle()
last_tune = 1
endcase
Delay(9)
until KeyPressed()
end

proc Main()
Message("Playing ... (Press any
key to stop)")
do_music_part()
while KeyPressed()
GetKey()
endwhile
Message("Stopped.")
Delay(36)
end


-----Oorspronkelijk bericht-----
Van: sem...@googlegroups.com [mailto:sem...@googlegroups.com] Namens
Heijer, Rob den
Verzonden: vrijdag 13 november 2009 9:41
Aan: sem...@googlegroups.com
Onderwerp: [TSE] Re: copying irregular column data neatly between two other
columns


Larry

unread,
Nov 15, 2009, 10:46:53 AM11/15/09
to sem...@googlegroups.com
Hi, Rob (too).

This is another reason to produce a 'useless' macro. :) Had I not put it up,
you may not have mentioned music sounds in just the way you did, and Carlo
may not have put up the neat music macro he did.

You never know how insignificant things can touch the right mind and produce
something new, unique, or useful.

Speaking of sound, I have to use them when working up a macro to let me know
when it does things and what it does. I also use lots of warn()ing boxes and
message()s to keep me informed, especially with open-ended loops. I often
pretend that I know what I am doing when I write a macro, and when I do, I
almost always pay a price and have to have Windows close TSE to kill off a
runaway macro. :(

Anyway, I tried to play around with sounds to use in the macros, deciding on
low for mistakes, and high for successes.

I tried to duplicate the old WS_FTP program "Uh-Oh" sound when it could not
access an ftp site, but never figured it out. It would also be nice to be
able to do what Peter Frampton does with his guitar...make TSE 'talk'
sounds. :)

--------------------------------------------------

Carlo Hogeveen

unread,
Nov 15, 2009, 1:31:05 PM11/15/09
to sem...@googlegroups.com

Speaking about making TSE talk, some people might not know yet that you can
play .wav files from a TSE macro.

For an example see the type.zip macro on Semware's download page.

So you search an appropriate message in .wav format on the internet, or if
your computer has a microphone you can record your own message in .wav
format, and have your macro play .wav messages to report the macro state's
or respond to a user action.

Have fun,
Carlo

From: sem...@googlegroups.com [mailto:sem...@googlegroups.com] On behalf
of Larry
Subject: [TSE] Re: Music (Was: copying irregular column data neatly between
two other columns)

...

Heijer, Rob den

unread,
Nov 16, 2009, 2:58:58 AM11/16/09
to sem...@googlegroups.com
Hi Larry,

For simple tasks like this, try this:

string cTab = Chr(9)
lReplace('{[0-z]#}[ '+ cTab + ']#{[0-z]#}[ ' + cTab + ']#{[0-z]#}', '\2' + cTab + '\1' + cTab + ' \3', 'lx')

in a macro...
it swaps word 1 and 2; the original may be space and tab separated; the result will be tab separated.

knud van eeden

unread,
Nov 16, 2009, 8:47:21 AM11/16/09
to sem...@googlegroups.com
Together with using tabs if applicable have maybe a look in the help at the 'Format()' command
 
I use that very versatile command a lot, e.g. 
to create tables with fixed given column width.
 
E.g. to create 1 row of a table with a fixed width of 10 characters, 30 characters and 40 characters:
 
PROC Main()
 Warn( Format( "COLUMN1":-10, "COLUMN2":30, " ":5, "COLUMN3":-40 ) )
 Warn( Format( "test1":-10, "test2":30, " ":5, "test3":-40 ) )
END
 
with friendly greetings,
Knud van Eeden



Larry

unread,
Nov 16, 2009, 9:56:47 AM11/16/09
to sem...@googlegroups.com
Thanks, Rob. I will put this into my regular expression help file for future
reference.

I know regular expression is a powerful tool. It's just incomprehensible to
me. I guess that is why I prefer using the intuitive SAL to write simple
macros that will accomplish the same thing.

Seems I remember a few years ago someone mentioned something about writing
an intuitive language for regular expressions, but I guess it never
happened. :)

--------------------------------------------------
From: "Heijer, Rob den" <rob.den...@capgemini.com>

Sent: Monday, November 16, 2009 1:58 AM


To: <sem...@googlegroups.com>
Subject: [TSE] Re: copying irregular column data neatly between two other
columns

>
> Hi Larry,
>

Larry

unread,
Nov 16, 2009, 10:00:42 AM11/16/09
to sem...@googlegroups.com
Thanks, Knud. I use format() a lot, but decided to do something else for
this specific chore, something that did not require me to come up with
column positions. The later 'spread columns' macro was the same way and came
from the irregular column sorting macro I did a couple of years ago. I call
the new one my 'column exploder'. :) It's cute to see delimited data 'blow
up' into perfect columns. :)

--------------------------------------------------
From: "knud van eeden" <knud_va...@yahoo.com>
Sent: Monday, November 16, 2009 7:47 AM


To: <sem...@googlegroups.com>
Subject: [TSE] Re: copying irregular column data neatly between two other
columns

>

knud van eeden

unread,
Nov 16, 2009, 10:45:51 AM11/16/09
to sem...@googlegroups.com
> I know regular expression is a powerful tool. It's just incomprehensible to me.
> I guess that is why I prefer using the intuitive SAL to write simple macros that will accomplish > the same thing.
> Seems I remember a few years ago someone mentioned something about writing an intuitive
> language for regular expressions, but I guess it never happened. :)

Maybe start playing with
LFind( ..., "x" ) and
LReplace( ..., "x" ) or
in the Find / Replace menu using the "x' option.

I use this techniques continuously when searching and replacing and writing and designing the simplest possible macros according to minimalist design.

It is more working with *patterns* than with verbatim or literal things.

E.g. searching for all lines which contain Larry with something in between and then Hayes.

You use most often

.* which means any character zero or more times

.+ which means any character one or more times (so that character should at least occur once, typically a space)

See TSE help 'regular expressions' for more options.

So searching for the first line which contains Larry followed by whatever character followed by Hayes would become something like

PROC Main()
 LFind( "Larry.*Hayes", "x" )
END

===

To extract the found information, you can use tags { } and GetFoundText()

For example if I want to extract the text between Larry and Hayes, I insert one or more tags. The first one you get with GetFoundText( 1 ), the second one with GetFoundText( 2 ), and so on.
Very powerful and I use this method very often. E.g. to analyze log files.

PROC Main()
 LFind( "Larry{.*}Hayes", "x" )
 Warn( GetFoundText( 1 ) )
END

This might maybe give further ideas.

withf friendly greetings,
Knud van Eeden



Larry

unread,
Nov 17, 2009, 7:44:53 AM11/17/09
to sem...@googlegroups.com
I have used some of the simpler regular expression tools, but I usually have
to look them up in MyHelp to get them right.

The question occurs to me, are there things that regular expression can do
that cannot be done with a macro? Even Find() and Replace() can be written
as macros and have features added to them. They run slower than the built-in
commands, but they work and can do things that the built-in commands cannot.

To be honest, it gave me a headache just looking at the regular expression
Rob offered. I'm sure it would be useful, but it gave me temporary
tangle-brain trying to figure it out. :)

I tend to be a simple person who does simple things. Stuff like regular
expressions, dll's, argument passing between procs, and other things are
scary like bears that would eat you alive. Still, with SAL, I have been able
to gather some macro-berries in my basket near the bear's cave. :)

The Shuttle Atlantis just made it safely to orbit in her next-to-last flight
before retirement. Fortunately for all of us, there are those among us who
understand regular expression and orbital mathematics and pixel engineering.
I am so grateful for all of you folks. You make life wonderful.

--------------------------------------------------
From: "knud van eeden" <knud_va...@yahoo.com>

Sent: Monday, November 16, 2009 9:45 AM


To: <sem...@googlegroups.com>
Subject: [TSE] Re: copying irregular column data neatly between two other
columns

>

Heijer, Rob den

unread,
Nov 17, 2009, 7:54:32 AM11/17/09
to sem...@googlegroups.com
Hi Larry,

My regular expression looked a bit like an exploded hedgehog.
Still, it's quite simple... Look at it:

lReplace('{[0-z]#}[ '+ cTab + ']#{[0-z]#}[ ' + cTab + ']#{[0-z]#}', '\2' + cTab + '\1' + cTab + ' \3', 'lx')

[0-z] means: Any digit or letter (and a bit in between that does not hurt)
[0-z]# means: same, a number of times but at least once.
[ <tab>]# means: any combination of spaces and tabs; again, at least one.

Now, {} treats anything as a group. You can use the group in the replacement string. So,
{[0-z]#} is the first word. You find it in the replacement string as \1 .
So, the replacement string is something like
"second word" <tab> "first word" <tab> "third word".


The reason that the range from 0 to z gives you "all digits and letters" is because of the values in the Ascii-table. "0" = 48, "9" = 57, "A" = 65, "Z" = 90, "a" = 97, "z" = 122.
From 48 to 122 covers them all, plus a few stowaways.

cheers,
Rob.

Rob den Heijer / Capgemini BAS B.V. / Voorburg
Application Developer II Sr. / BAS-CAM BU1
06 5266 8698/ rob.de...@capgemini.com

-----Original Message-----
From: sem...@googlegroups.com [mailto:sem...@googlegroups.com] On Behalf Of Larry

Larry

unread,
Nov 17, 2009, 9:45:25 AM11/17/09
to sem...@googlegroups.com
You know, Rob, that makes perfect sense the way you wrote it out. I guess
that means I am a 'verbal' guy rather than an 'equation' guy. :) Maybe this
is why I understood "Paradise Lost" in graduate English but not differential
equations in calculus (couldn't recognise a curve by looking at an
equation). :)

I take from this that learning regular expression syntax is like learning
SAL...you just have to get your mind into it and it finally sinks in.

Thanks

--------------------------------------------------
From: "Heijer, Rob den" <rob.den...@capgemini.com>

Sent: Tuesday, November 17, 2009 6:54 AM


To: <sem...@googlegroups.com>
Subject: [TSE] Re: copying irregular column data neatly between two other
columns

>

Heijer, Rob den

unread,
Nov 18, 2009, 10:10:29 AM11/18/09
to sem...@googlegroups.com
Well - the fun of regular expressions is: you can learn them bit by bit. One bit today, one bit tomorrow - or next week.

One of the things I do quite often is: find empty lines (or delete them). It's as simple as this:
lFind('^$' , 'x')
because ^ is the symbol for "beginning of line" and $ is "end of line".

Another simple thing, usable by itself is: find warnings and errors. Like this:
lFind('{Warning}|{Error}', 'xi')

And yet another: find "I want to go shopping" but also "I want to go fishing" and "I want to go sky-diving" with just one expression. Remember that "." is "any character" and "*" is "as often as you like". So:
lFind('I want to go.*ing", "x") will find them all for you!

cheers,
Rob.


Rob den Heijer / Capgemini BAS B.V. / Voorburg
Application Developer II Sr. / BAS-CAM BU1
06 5266 8698/ rob.de...@capgemini.com

-----Original Message-----
From: sem...@googlegroups.com [mailto:sem...@googlegroups.com] On Behalf Of Larry

knud van eeden

unread,
Nov 18, 2009, 12:17:54 PM11/18/09
to sem...@googlegroups.com
> I know regular expression is a powerful tool. It's just incomprehensible to me.

http://www.knudvaneeden.com/tinyurl.php?urlKey=url000360

Reply all
Reply to author
Forward
0 new messages