Re: Fun with coercing to string
Re: Fun with coercing to string
- Subject: Re: Fun with coercing to string
- From: Nigel Garvey <email@hidden>
- Date: Wed, 21 Feb 2001 10:30:54 +0000
Chris Nebel wrote on Tue, 20 Feb 2001 15:27:35 -0800:
>
"Stephen Swift (aka Burnum)" wrote:
>
> WHAT DOESN'T WORK:
>
> set ThisMonth to month of (current date)
>
> display dialog "We are in the month of " & ThisMonth
>
> --Can't make February into a string
>
>
>
> According to my AppleScript reference tables current date command is
>
> coercible to a list of its properties. How come I can use the month in a
>
> dialog box by itself but when I try to put it with another string
>
> AppleScript tells me 'February can't be a string'? And How come it will
>
> take the day of the current date and make it into a string? Thanks.
[...]
>
If you're sticking with Mac OS 8.1 and you still want to get the month as a
>
string, either write a handler to do it yourself, or use one of the many
>
date-formatting scripting additions.
One way to code round this, which looks as though it should work with Mac
OS 8.1, is a variation of an old trick:
on monthStr(theMonth)
try
theMonth as string -- gives an error prior to Mac OS - er - 8.5.1 ?
on error msg -- "Can't make February into a string"
word 3 of msg
end try
end monthStr
monthStr(month of (current date))
This also works for weekdays, so perhaps the variable names should be
different. The result (when obtained from the error message) is in
formatted text, but I don't think this would normally be a problem.
NG