[NTLK] Holidays code

From: John Charlton (johncharlton_at_mac.com)
Date: Sat Dec 17 2005 - 20:45:24 PST


For those of you (Sonny & Ronnie) who wanted a look at the code I wrote, here are the important bits.

The dates are put into a file formatted like:

DefConst
(
        'newDates,
        [
                "12/10/05", "A Date",
                "12/11/05", "B Date",
                "12/12/05", "C Date",
        ]
);

The main layout is a protoApp with one button called "clickMe", which has the following buttonClickScript:

func() begin
    if not done then begin
        cal := GetRoot().calendar;

        // Loop through entries in newDates.f two by two
        for i := 0 to Length( newDates ) - 1 by 2 do begin
            local date := StringToDate( newDates[i] );
            local mtgText := newDates[i+1];

            // Check for existing events on that day with the same text
            if not cal:FindAppointment( mtgText, nil, date, 'Event, nil ) then
                // Create a new event, and add a 'createdBy' slot for possible future deletion
                cal:AddEvent( mtgText, date, nil, nil ).createdBy := kAppSymbol;
        end;

        // Change the button text and format to show success
        clickMe.text := "Done";
        SetValue( clickMe, 'viewFormat, viewFormat - vfFrameBlack + vfFrameWhite );

        done := true;
    end;
end;

It's not much, and certainly could be improved, but it works OK. It would be easy enough, by adding other array names and buttons, to have a more modular Holidays for different countries and cultures. Getting that information though is a chore, but think of the rewards!

It's a good starter project for someone, and got me on the road to programming in Newtonscript. Now if only I could find some time to work on my list of programs I'd write if I could find some time...

Happy "Holidays 2006" everyone.

--jc

-- 
This is the NewtonTalk list - http://www.newtontalk.net/ for all inquiries
Official Newton FAQ: http://www.chuma.org/newton/faq/
WikiWikiNewt for all kinds of articles: http://tools.unna.org/wikiwikinewt/


This archive was generated by hypermail 2.1.5 : Sat Dec 17 2005 - 22:30:05 PST