Time to upgrade my technique...

Jim Ault JimAultWins at yahoo.com
Tue Jun 10 11:55:06 EDT 2008


Here are some skeleton techniques that can be applied to your set of tasks.
<full listing of original appears below my code>

Jim Ault
Las Vegas

----------------- start code -------------

on doJimsTasks
  --Jim Ault    6.10.08    for    Jim Cowardine
  --partial script to show techniques
  --will not run, but shows example techniques
  --this is not the only way to build a fast Rev routine
  
  put fld 1 into mainList  --use variables in RAM
  put 0 into i
  put 1 into j
  put empty into eventOutputList --final listing
  put empty into currentEvent -- each line we want to fill
  --this is added to eventOutputList at the end of the loop
  --then eventOutputList is put into field 2 at the finish
  
  --set up a comma listing of keywords for later
  put "Dartmouth,Burnside,Bedford,Sackville,Kentville," into cityList
  put "Port  Hawksbury,Truro,Bridgewater,Tantallon," after cityList
  put "Glen Haven,Hubbards,Bayers Lake,Cole  Harbour" after cityList
  
  --now create a list of only those lines that qualify
  filter mainList with "*BEGIN:VEVENT*"
  --now the only lines remaining are the ones we want
  put mainList into keepers --this is a better name, but optional
  
  -- I use LNN to be the unmodifiable variable to read
  repeat for each line LNN in keepers
    add 1 to i
    if LNN contains "SUMMARY" then
    end if
    if LNN contains "LOCATION" then
    end if
    if LNN contains "DSTART" then
    end if
    if LNN contains "END:VEVENT" then
    end if
     
     
    if holdLine is 1 then
      put eventDate into item 2 of currentEvent
      put locationName into item 5 of currentEvent
       
      set the itemDel to comma
      if item 5 of currentEvent is among the items of cityList then
        put item 5 of currentEvent into item 6 of currentEvent
      end if
       
      put currentEvent into line j of eventOuputList
       
    end repeat
    put eventOuputList into field 2
    set the itemdelimiter to ","
    sort lines of field 2 by item 7 of each
    sort lines of field 2 dateTime by item 2 of each
     
     
  end doJimsTasks

------------  end code  -----------------


On 6/10/08 7:53 AM, "Jim Carwardine" <jim at oyfconsulting.com> wrote:

> Hi Folks... I hope this isn't asking too much.  I have found using the
> docs to be less than satisfying when trying an alternative coding
> technique.  I guess I fall into the old dog, actually the old
> Hypercard dog, trying to learn the new Rev tricks.
> 
> I just wrote a quick and dirty script to parse out an iCal calendar
> saved as a text file to feed my car expense calculator which was
> published a few months ago in a Rev newsletter.  The script is very
> slow and I was intrigued to know how to speed it up as I am aware that
> I am using very archaic scripting techniques.
> 
> Here is my script.  It's relatively short and contains almost all of
> my favourite coding patterns.  If anyone has the inclination, perhaps
> you could point out how I might make use of Revs improvements over
> Hypercard...
> 
> It has to do with better ways to handle repeating actions and better
> ways to handle lists... Thanks in advance... Jim
> 
> --> all handlers
> 
> on mouseUp
>      put 0 into eventMark -- didn't end up using this for anything by
> a switch
>      put 1 into j
>      put empty into eventLine
>      put empty into field 2
>      repeat with i = 1 to the number of lines of field 1
>          if line i of field 1 contains "BEGIN:VEVENT" then -- found an
> event
>              put 1 into eventMark
>              next repeat
>          end if
>          if eventMark > 0 then -- we are parsing an event now
>              breakpoint
>              if line i of field 1 contains "SUMMARY:" then -- found
> the event name
>                  put 2 into eventMark
>                  set the itemdelimiter to ":"
>                  put item 2 of line i of field 1 into eventName --
> hold event name
>                  next repeat
>              end if
>              if line i of field 1 contains "LOCATION:" then -- found
> the event location
>                  put 3 into eventMark
>                  if line i of field 1 contains "\," then replace "\, "
> with " " in line i of field 1
>                  set the itemdelimiter to ":"
>                  put item 2 of line i of field 1 into locationName --
> hold event location
>                  next repeat
>              end if
>              if line i of field 1 contains "DTSTART;" then -- found
> the event location
>                  put 4 into eventMark
>                  set the itemdelimiter to ":"
>                  put char 1 to 4 of item 2 of line i of field 1 into
> eventYear -- hold event year - yyyymmdd
>                  put char 5 to 6 of item 2 of line i of field 1 into
> eventMonth -- hold event month - yyyymmdd
>                  put char 7 to 8 of item 2 of line i of field 1 into
> eventDay -- hold event day - yyyymmdd
>                  put char 10 to 13 of item 2 of line i of field 1 into
> eventTime -- hold event time
>                  next repeat
>              end if
>          end if
>          if line i of field 1 contains "END:VEVENT" then -- found an
> event ending
>              set itemdelimiter to ","
>              if eventYear = "2007" then
>                  -- if eventMonth „ "10" then
>                  put eventMonth & "/" & eventDay & "/" & eventYear
> into eventDate
>                  put 1 into holdLine
>                  -- else put 0 into holdLine
>              else put 0 into holdLine
> 
>              if holdLine is 1 then
>                  put eventDate into item 2 of line j of field 2
>                  if locationName is empty then put "Halifax" into
> locationName
>                  put locationName into item 5 of line j of field 2
>                  put " - " & eventName after item 5 of line j of field 2
>                  put empty into item 6 of line j of field 2
>                  if item 5 of line j of field 2 contains "Dartmouth"
> then put "Dartmouth" into item 6 of line j of field 2
>                  if item 5 of line j of field 2 contains "Burnside"
> then put "Burnside" into item 6 of line j of field 2
>                  if item 5 of line j of field 2 contains "Bedford"
> then put "Bedford" into item 6 of line j of field 2
>                  if item 5 of line j of field 2 contains "Sackville"
> then put "Sackville" into item 6 of line j of field 2
>                  if item 5 of line j of field 2 contains "Kentville"
> then put "Kentville" into item 6 of line j of field 2
>                  if item 5 of line j of field 2 contains "Port
> Hawksbury" then put "Port Hawksbury" into item 6 of line j of field 2
>                  if item 5 of line j of field 2 contains "Truro" then
> put "Truro" into item 6 of line j of field 2
>                  if item 5 of line j of field 2 contains "Bridgewater"
> then put "Bridgewater" into item 6 of line j of field 2
>                  if item 5 of line j of field 2 contains "Tantallon"
> then put "Tantallon" into item 6 of line j of field 2
>                  if item 5 of line j of field 2 contains "Glen Haven"
> then put "Glen Haven" into item 6 of line j of field 2
>                  if item 5 of line j of field 2 contains "Hubbards"
> then put "Hubbards" into item 6 of line j of field 2
>                  if item 5 of line j of field 2 contains "Bayers Lake"
> then put "Bayers Lake" into item 6 of line j of field 2
>                  if item 5 of line j of field 2 contains "Cole
> Harbour" then put "Cole Harbour" into item 6 of line j of field 2
>                  if item 5 of line j of field 2 contains "airport"
> then put "airport" into item 6 of line j of field 2
>                  put eventTime into item 7 of line j of field 2
>                  if line j of field 2 contains "\" then replace "\"
> with empty in line j of field 2
>                  put return after line j of field 2
>                  add 1 to j
>                  put empty into eventDate
>                  put empty into locationName
>                  put empty into eventName
>                  put empty into eventYear
>                  put empty into eventMonth
>                  put empty into eventDay
>                  put empty into eventTime
>              end if
>              put 0 into eventMark
>              -- end if
>          end if
>          if the optionkey is "down" then exit repeat
>      end repeat
>      set the itemdelimiter to ","
>      sort lines of field 2 by item 7 of each
>      sort lines of field 2 dateTime by item 2 of each
> end mouseUp
> Jim Carwardine,
> President & CEO
> OYF Consulting
> Ph. 902.823.2339 / 866.601.2339
> Fx. 902.823-2139
> <www.StrategicDoing.com>
> StrategicDoing: Execution depends on employees.
> Strategic Partner with HiringSmart Canada Ltd.





More information about the use-livecode mailing list