The problem, strangely enough, is that DATE1 is a STRING, not a DATE.
Unfortunately, in the CI, there is no such (intrinsic) data type known as
"date" -- it just happens to work WITHIN an expression "just to fool you" ;)
Seriously, though, that's the basic problem. MPEX is just following the
known CI-available data types, of which there is STRING and INTEGER, but no
DATE. Within an MPEX **EXPRESSION** however, there are "other types"
available, namely, REAL and DATE. MPEX also does implicit type conversion
when setting variables, but (unfortunately) not when referencing them.
Thus, when you type
%SETVAR DATE1 DATEBUILD(<some parms>)
DATE1 is actually a STRING containing the textual representation of whatever
the results of the "datebuild" command produced. When you next try to
reformat it via
%SETVAR DATE2 STRWRITE(DATE1:"%Y4")
MPEX naturally complains about attempting to use DATE formatting
characteristics against a STRING variable.
There are two ways you can circumvent this problem:
1) combine the operations:
%SETVAR DATE1 STRWRITE(DATEBUILD(<parms>),<format>)
2) de-reference the variable:
%SETVAR DATE1 DATEBUILD(<parms>)
%SETVAR DATE2 STRWRITE(![DATE1],<format>)
Unfortunately, method 2 rarely works -- usually, you'll get an error about
specifying dates in MDY format instead of YMD (or the other way around).
Again, this is the same as the first problem -- DATE1 is a string containing
the textual representation of the result of the initial function,
unfortunately (again), the "textual representation" does not default to the
same format you use to SPECIFY explicit dates...
EAGLE: %setvar date1 datebuild(hpyear, hpmonth, hpday)
EAGLE: %showvar date1
DATE1 = 00/07/06
EAGLE: %calc strwrite(!date1,"%4Y")
Processing STRWRITE(00/07/06,"%4Y")
^
Error: Expected date in MM/DD/YY format, not 00/07/06
EAGLE: %
Fortunately, there is still a solution to this:
EAGLE: %help dateparse
DATEPARSE (S1,S2) [DATE] Parses the string S1 as a date; S2 specifies
the
format in which S1 is supposed to be, either
'YMD', 'MDY' or 'DMY'. (The date may have
either
a 2- or 4-digit year and may exclude the
slashes). DATEPARSE('03/30/91','MDY') is
91/03/30; DATEPARSE('19910330','YMD') is also
91/03/30.
EAGLE: %calc strwrite(dateparse(date1,"YMD"):"%4Y")
2000
EAGLE: %
Tom (who just realized he used "hpday" instead of "hpdate" for the day of
the month) Emerson
> -----Original Message-----
> From: Larry Barnes [mailto:[log in to unmask]]
> Sent: Friday, July 21, 2000 2:50 PM
> To: [log in to unmask]
> Subject: [HP3000-L] MPEX question
>
>
> Below is a test attempting to use 'datebuild' and 'strwrite'. I have
> used it in the past without a problem. Can anyone see what is wrong
> with my syntax?
>
> %
> %SETVAR DATE1 DATEBUILD(!HPYEAR,!HPMONTH,!HPDATE)
> %
> %SETVAR DATE1 STRWRITE(DATE1:'%4Y')
> Error: Format specifier contained %4Y, expected one of:
> GARBAGE CENTER
> Error: Bad format specifier.
>
>
> thanks in advance,
> --
> Larry Barnes
> Director of I.T.
> Mitek Corp.
> 602-438-4545 X 1366
> Phoenix, AZ 85040
>
> Check Us Out !
> http://www.mitekcorp.com
> http://www.atlassound.com
> http://www.coustic.com
> http://www.mtxaudio.com
> http://www.xtant.com
> http://www.dcmspeakers.com
>
|