Hi all,
Thanks to the excellent advice I've received I now have (I believe) a
working and bug free macro. One difficult (for me) piece of it was a macro
called "cutspace" which scans a string until it finds either a fullstop or
a space (let's call it a chunk) and gathers all the tones (indicated by
1234 in the string) and puts them at the end of the chunk. It works its way
through the string moving the tones (if they are present) to the correct
location. This function is only a small part of a much larger one which
encodes strings in such a was as they are sorted correctly. The encoding
are generated in a different column from the originals and the sort is
based on that column (invisible to the reader, of course).
Here's the code. If there are any OO Basic features I've missed that would
simplified things, I'd be grateful to hear about them.
[code]
Function cutspace(ProcessString) as String
        Dim Index as Integer
        Dim OldIndex as Integer
        Dim Position As Integer
        Dim Ch As String
        Dim Chunk As String
        Dim Res As String
        Dim Lft As String
        Dim Per As String
        Dim mrk As String
        const Tones = "1234"
        Per = ". "
        '###### Get rid of easy cases - no space/fullstop
        if myany(". ", ProcessString) = False then
                        cutspace = movetones(processString)
                        Exit Function
        End if
        OldIndex=0
        'Start point of chunk must be OldIndex+1
        'Then OldIndex becomes Index
        '###### Now we have to work
        For Index = 1 to len(ProcessString)
                Ch = mid(ProcessString,Index,1) 'Get a char from ProcessString
                Position = instr(Per,Ch) 'See if char is fullstop or blank
                If Position <> 0 then  'if we've found fullstop or blank
                        mrk = Ch 'keep track of which separator we found
                        Chunk = mid(ProcessString, OldIndex+1, 
Index-OldIndex-1) 'break off a
chunk of ProcStr
                        Lft = Lft + movetones(Chunk) 'add the chunk to Lft
                        OldIndex = index 'move our starting point after the 
last space/fullstop
                end if
        Next Index
        Res = mid(ProcessString, OldIndex + 1, 999) 'from after space to end
        if myany(tones, res) then
                ProcessString = Lft + mrk + movetones(Res)
        else
                ProcessString = Lft + mrk + Res
        Endif
        cutspace=ProcessString
end Function
[/code]

Just for comparison, here's pretty much the same program written in Icon:
[code]
procedure main(args)
        line := args[1]
        lft := ""
        seps := ' .'
        line ? while (chunk := tab(upto(seps)) & sp := move(1) & mypos := &pos) 
do
{
                lft ||:= (movetone(chunk) || sp)
        }
        myline := lft || movetone(line[mypos:0])
        write(myline)
end

Thanks again to everyone.
Jonathan
-- 
Registerd Linux user #445917 at http://counter.li.org/
Please do not send me copies of list mail. I read the lists. Thanks!


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to