AutoHotkey Community

It is currently May 26th, 2012, 3:39 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: June 25th, 2005, 5:48 am 
Offline

Joined: June 9th, 2005, 8:27 am
Posts: 31
Location: Germany near Cologne
    Local Variables for fDate_DayNumber()
    --------------------------------------------------
    datezero_1582_10_15[6 of 6]: 578100
    datezero_1582_10_15|[0 of 0]:
    Day[2 of 6]: 25
    fDate_DayNumber[0 of 0]:
    Month[1 of 1]: 6
    Year[4 of 6]: 2005
but: when I copied this from the ListVars window I saw: the pipe symbol "|" is really a CR !

Code:
fDate_DayNumber( Year, Month, Day )
{

   datezero_1582_10_15 := 578100
   fDate_DayNumber :=
      (
      - datezero_1582_10_15
      - 1
      )
ListVars
}

/*********************************************
 *   File:  xx_test.ahk
 *   Autor: KalleW
 *   Datum: 2005-06-25 05:58
 *
 *********************************************
 */

   #Include inc_autoreload.ahk
   #Include inc_autoreload_error.ahk
   ;#Include daynr.ahk
   Return

^!X::     ; <Ctrl-Alt-X>
Year := 2005
Month := 6
Day := 25

DayNr := fDate_DayNumber( Year, Month, Day )

tooltip %year% - %month% - %day% := %daynr%

return


the ListVars with the full function showed more of the pipes:
    Local Variables for fDate_DayNumber()
    --------------------------------------------------|||
    ...
    datezero_1582_10_15[6 of 6]: 578100
    ...

Code:
xfDate_DayNumber( Year, Month, Day )
{

   datezero_1582_10_15 := 578100
   if ( year >= 50 AND year <= 99 ) then
      year_4byte  := year + 1900
;
   else if ( year >= 00 AND year <= 49 ) then
      year_4byte  := year + 2000
;
   else
      year_4byte  := year
;
;  -1------------------------------------------------------------
;
   if ( month <= 2 ) then
   {
      corr_month      := 0
      corr_leapyear   := + ( year_4byte-1 ) / 4
      corr_100_years  := - FLOOR( year_4byte-1 / 100.)
      corr_400_years  := + FLOOR( year_4byte-1 / 400.)
   }
   else
   {
      corr_month      := - FLOOR( 0.4 * month + 2.3)
      corr_leapyear   := + year_4byte/4
      corr_100_years  := - FLOOR( year_4byte / 100.)
      corr_400_years  := + FLOOR( year_4byte / 400.)
   }
;
;  -3------------------------------------------------------------
;
   raw_daynr
      (
      := year_4byte * 365
      + 31 * ( month - 1 )
      + day
      )
   correction
      (
      := corr_month
      + corr_leapyear
      + corr_100_years
      + corr_400_years
      )
   fDate_DayNumber :=
      (
       raw_daynr
      + correction
      - datezero_1582_10_15
      - 1
      )
   ListVars
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 26th, 2005, 3:40 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Thanks for the examples. It happens even in a simple example like the following, which creates a variable containing a linefeed character as part of its name:

var`n = Test String.

Although this is definitely unintended behavior, perhaps it shouldn't be fixed to avoid breaking any existing scripts that might be using it intentionally or otherwise.

To work around it, specify "Join" in your continuation sections to avoid the extra linefeeds:

fDate_DayNumber :=
(Join
- datezero_1582_10_15
- 1
)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 26th, 2005, 1:33 pm 
Offline

Joined: June 9th, 2005, 8:27 am
Posts: 31
Location: Germany near Cologne
Chris wrote:
Although this is definitely unintended behavior, perhaps it shouldn't be fixed ...


Yes, I see the problem with old scripts.
But I think continuation lines exist in nearly all prog languages and none of these need such a workaround as "Join".

So I think that nearly everyone using this for the first time falls into that pit (and searches a long time - it took me half a day until I found out).

If someone really wants a variable with a return this person should use your example with "var`n =".

A side effect like this should not be preserved in a language.
So the change should be (of cause) marked in the change log and be done.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 27th, 2005, 4:30 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
KalleW wrote:
But I think continuation lines exist in nearly all prog languages and none of these need such a workaround as "Join".
The problem is that the continuation section is not designed to build expressions (you can start a line with &&/||, "and/or", and "." to extend expressions). It's really intended for relatively long sections such as doing a FileAppend of a dozen lines.

I would adjust continuation sections to eliminate this side-effect if it were easy. But due to the parsing stages done by the program, I think it would be quite difficult and might involve an unwanted increase in code size.

Thanks for your comments. I will keep an eye out for a possible solution.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 27th, 2005, 8:18 am 
Offline

Joined: June 9th, 2005, 8:27 am
Posts: 31
Location: Germany near Cologne
Thanks, Chris, for taking the time to think about this problem.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group