[Gambas-user] Why syntax error?

2015-08-13 Thread Sprachschule Eilert
This produces a syntax error, but it doesn't tell me why:

Private Const $TB As String = Chr$(9)

If I leave "Const" away, it runs, so it shouldn't be the $TB which 
disturbs, as it is accepted as a variable naming. The rest should be ok, 
too. So I can't find any reason...

Thanks for any hint

Rolf

--
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Why syntax error?

2015-08-13 Thread Adrien Prokopowicz
Le Thu, 13 Aug 2015 11:19:09 +0200, Sprachschule Eilert  
 a écrit:

> This produces a syntax error, but it doesn't tell me why:
>
> Private Const $TB As String = Chr$(9)
>
> If I leave "Const" away, it runs, so it shouldn't be the $TB which
> disturbs, as it is accepted as a variable naming. The rest should be ok,
> too. So I can't find any reason...
>
> Thanks for any hint
>
> Rolf
>

This is because calling functions is not allowed when defining a constant
value.

In your case, you have to use a string containing your character using an
escape code :

Private Const $TB As String = "\x09" 'Contains the ASCII character 9

Or, even better in your case :

Private Const $TB As String = "\t" 'Contains the TAB character (ASCII 9)

But I agree that the error message is not very clear ...

Regards,

-- 
Adrien Prokopowicz

--
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Why syntax error?

2015-08-13 Thread Adrien Prokopowicz
Le Thu, 13 Aug 2015 12:05:06 +0200, Adrien Prokopowicz  
 a écrit:

> Le Thu, 13 Aug 2015 11:19:09 +0200, Sprachschule Eilert  
>  a écrit:
>
>> This produces a syntax error, but it doesn't tell me why:
>>
>> Private Const $TB As String = Chr$(9)
>>
>> If I leave "Const" away, it runs, so it shouldn't be the $TB which
>> disturbs, as it is accepted as a variable naming. The rest should be ok,
>> too. So I can't find any reason...
>>
>> Thanks for any hint
>>
>> Rolf
>>
>
> This is because calling functions is not allowed when defining a constant
> value.
>
> In your case, you have to use a string containing your character using an
> escape code :
>
>   Private Const $TB As String = "\x09" 'Contains the ASCII character 9
>
> Or, even better in your case :
>
>   Private Const $TB As String = "\t" 'Contains the TAB character (ASCII 9)
>
> But I agree that the error message is not very clear ...
>
> Regards,
>

The error messages are much more clear now in revision #7222 !

-- 
Adrien Prokopowicz

--
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] datediff problem

2015-08-13 Thread Adrien Prokopowicz
Le Mon, 10 Aug 2015 13:41:17 +0200, Jussi Lahtinen
 a écrit:

> Sorry to say, but this doesn't seem to be fixed.
>
> ? DateDiff(Now, DateAdd(Now, gb.Day, 2), gb.Day)
> 1
>
>
> Jussi
>
> On Sat, Aug 1, 2015 at 7:16 PM, Benoît Minisini <
> gam...@users.sourceforge.net> wrote:
>
>> Le 01/08/2015 17:52, Benoît Minisini a écrit :
>> > Le 01/08/2015 17:33, nando a écrit :
>> >> Here's an example.
>> >>
>> >>Dim FirstDate as Date
>> >>
>> >>FirstDate = Date(2015, 1, 1, 0, 0, 0, 0)
>> >>Print DateDiff(firstdate, Date(2015, 8, 1, 00, 00, 00), gb.day)   
>> 'ok
>> >>Print DateDiff(firstdate, Date(2015, 8, 1, 00, 00, 01), gb.day)   
>> 'ok
>> >>Print DateDiff(firstdate, Date(2015, 8, 1, 03, 59, 59), gb.day)   
>> 'ok
>> >>Print DateDiff(firstdate, Date(2015, 8, 1, 04, 00, 00), gb.day)
>> >> 'Wrong
>> >>Print DateDiff(firstdate, Date(2015, 8, 1, 11, 21, 51), gb.day)
>> >> 'Wrong
>> >>
>> >> 212
>> >> 212
>> >> 212
>> >> 213  <---Wrong  should be 212
>> >> 213  <---Wrong  should be 212
>> >>
>> >> Of course, this is looks like it might be a TimeZone problem.
>> >> I am in GMT -5 but daylight savings during the summer it is -4
>> >>
>> >> Am I correct to say this is not correct operation?
>> >>
>> >> -Nando
>> >>
>> >>
>> >
>> > Argh, a just too late bug! You did that to spoil my holidats? 8-o
>> >
>>
>> OK, I couldn't let you alone. I have updated the Gambas 3.8 source
>> package with the fix for that bug.
>>
>> Regards,
>>
>> --
>> Benoît Minisini

That's weird, but the examples given (both jussi's and nando's) all work
correctly before Benoît's fix (pre-7212), but not after (post-7212) !

Am I missing something completely obvious, or do you get the same behavior
?

Here's my test code :

Dim FirstDate As Date

 FirstDate = Date(2015, 1, 1, 0, 0, 0, 0)
 Print DateDiff(firstdate, Date(2015, 8, 1, 00, 00, 00), gb.day)
 Print DateDiff(firstdate, Date(2015, 8, 1, 00, 00, 01), gb.day)
 Print DateDiff(firstdate, Date(2015, 8, 1, 03, 59, 59), gb.day)
 Print DateDiff(firstdate, Date(2015, 8, 1, 04, 00, 00), gb.day)
 Print DateDiff(firstdate, Date(2015, 8, 1, 11, 21, 51), gb.day)
 Print DateDiff(firstdate, DateAdd(firstdate, GB.Day, 2), GB.Day)

Output (Before 7212) :

212
212
212
212
212
2

Output (After 7212) :

211
212
212
212
212
1

-- 
Adrien Prokopowicz

--
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Why syntax error?

2015-08-13 Thread Rolf-Werner Eilert


Am 13.08.2015 16:06, schrieb Adrien Prokopowicz:
> Le Thu, 13 Aug 2015 12:05:06 +0200, Adrien Prokopowicz
>  a écrit:
>
>> Le Thu, 13 Aug 2015 11:19:09 +0200, Sprachschule Eilert
>>  a écrit:
>>
>>> This produces a syntax error, but it doesn't tell me why:
>>>
>>> Private Const $TB As String = Chr$(9)
>>>
>>> If I leave "Const" away, it runs, so it shouldn't be the $TB which
>>> disturbs, as it is accepted as a variable naming. The rest should be ok,
>>> too. So I can't find any reason...
>>>
>>> Thanks for any hint
>>>
>>> Rolf
>>>
>>
>> This is because calling functions is not allowed when defining a constant
>> value.
>>
>> In your case, you have to use a string containing your character using an
>> escape code :
>>
>>  Private Const $TB As String = "\x09" 'Contains the ASCII character 9
>>
>> Or, even better in your case :
>>
>>  Private Const $TB As String = "\t" 'Contains the TAB character (ASCII 9)
>>
>> But I agree that the error message is not very clear ...
>>
>> Regards,

Thank you very much for the explanation!

>>
>
> The error messages are much more clear now in revision #7222 !
>

Oh - I'm working with the last official version on this machine. But 
looking forward to see it soon :)

Rolf

--
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] datediff problem

2015-08-13 Thread adamn...@gmail.com
On Thu, 13 Aug 2015 16:22:13 +0200
"Adrien Prokopowicz"  wrote:

> Le Mon, 10 Aug 2015 13:41:17 +0200, Jussi Lahtinen
>  a écrit:
> 
> > Sorry to say, but this doesn't seem to be fixed.
> >
> > ? DateDiff(Now, DateAdd(Now, gb.Day, 2), gb.Day)
> > 1
> >
> >
> > Jussi
> >
> > On Sat, Aug 1, 2015 at 7:16 PM, Benoît Minisini <
> > gam...@users.sourceforge.net> wrote:
> >
> >> Le 01/08/2015 17:52, Benoît Minisini a écrit :
> >> > Le 01/08/2015 17:33, nando a écrit :
> >> >> Here's an example.
> >> >>
> >> >>Dim FirstDate as Date
> >> >>
> >> >>FirstDate = Date(2015, 1, 1, 0, 0, 0, 0)
> >> >>Print DateDiff(firstdate, Date(2015, 8, 1, 00, 00, 00), gb.day)   
> >> 'ok
> >> >>Print DateDiff(firstdate, Date(2015, 8, 1, 00, 00, 01), gb.day)   
> >> 'ok
> >> >>Print DateDiff(firstdate, Date(2015, 8, 1, 03, 59, 59), gb.day)   
> >> 'ok
> >> >>Print DateDiff(firstdate, Date(2015, 8, 1, 04, 00, 00), gb.day)
> >> >> 'Wrong
> >> >>Print DateDiff(firstdate, Date(2015, 8, 1, 11, 21, 51), gb.day)
> >> >> 'Wrong
> >> >>
> >> >> 212
> >> >> 212
> >> >> 212
> >> >> 213  <---Wrong  should be 212
> >> >> 213  <---Wrong  should be 212
> >> >>
> >> >> Of course, this is looks like it might be a TimeZone problem.
> >> >> I am in GMT -5 but daylight savings during the summer it is -4
> >> >>
> >> >> Am I correct to say this is not correct operation?
> >> >>
> >> >> -Nando
> >> >>
> >> >>
> >> >
> >> > Argh, a just too late bug! You did that to spoil my holidats? 8-o
> >> >
> >>
> >> OK, I couldn't let you alone. I have updated the Gambas 3.8 source
> >> package with the fix for that bug.
> >>
> >> Regards,
> >>
> >> --
> >> Benoît Minisini
> 
> That's weird, but the examples given (both jussi's and nando's) all work
> correctly before Benoît's fix (pre-7212), but not after (post-7212) !
> 
> Am I missing something completely obvious, or do you get the same behavior
> ?
> 
> Here's my test code :
> 
> Dim FirstDate As Date
> 
>  FirstDate = Date(2015, 1, 1, 0, 0, 0, 0)
>  Print DateDiff(firstdate, Date(2015, 8, 1, 00, 00, 00), gb.day)
>  Print DateDiff(firstdate, Date(2015, 8, 1, 00, 00, 01), gb.day)
>  Print DateDiff(firstdate, Date(2015, 8, 1, 03, 59, 59), gb.day)
>  Print DateDiff(firstdate, Date(2015, 8, 1, 04, 00, 00), gb.day)
>  Print DateDiff(firstdate, Date(2015, 8, 1, 11, 21, 51), gb.day)
>  Print DateDiff(firstdate, DateAdd(firstdate, GB.Day, 2), GB.Day)
> 
> Output (Before 7212) :
> 
> 212
> 212
> 212
> 212
> 212
> 2
> 
> Output (After 7212) :
> 
> 211
> 212
> 212
> 212
> 212
> 1
> 
> -- 
> Adrien Prokopowicz
> 
> --
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user

Confirmed at 7219 and I've added more output and tests:
  Dim FirstDate As Date
  Dim SecondDate As Date

  FirstDate = Date(2015, 1, 1, 0, 0, 0, 0)
  SecondDate = Date(2015, 8, 1, 00, 00, 00)

  Print "1 First:"; Format(FirstDate, "dd-mmm-yy hh:nn:ss:uu"); " ("; 
CFloat(FirstDate); ") Second:"; Format(SecondDate, "dd-mmm-yy hh:nn:ss:uu"); " 
("; CFloat(SecondDate); ") Diff:"; DateDiff(firstdate, SecondDate, gb.day); " 
("; CFloat(SecondDate) - CFloat(FirstDate); ")"

  SecondDate = Date(2015, 8, 1, 00, 00, 01)
  Print "2 First:"; Format(FirstDate, "dd-mmm-yy hh:nn:ss:uu"); " ("; 
CFloat(FirstDate); ") Second:"; Format(SecondDate, "dd-mmm-yy hh:nn:ss:uu"); " 
("; CFloat(SecondDate); ") Diff:"; DateDiff(firstdate, SecondDate, gb.day); " 
("; CFloat(SecondDate) - CFloat(FirstDate); ")"

  SecondDate = Date(2015, 8, 1, 03, 59, 59)
  Print "3 First:"; Format(FirstDate, "dd-mmm-yy hh:nn:ss:uu"); " ("; 
CFloat(FirstDate); ") Second:"; Format(SecondDate, "dd-mmm-yy hh:nn:ss:uu"); " 
("; CFloat(SecondDate); ") Diff:"; DateDiff(firstdate, SecondDate, gb.day); " 
("; CFloat(SecondDate) - CFloat(FirstDate); ")"

  SecondDate = Date(2015, 8, 1, 04, 00, 00)
  Print "4 First:"; Format(FirstDate, "dd-mmm-yy hh:nn:ss:uu"); " ("; 
CFloat(FirstDate); ") Second:"; Format(SecondDate, "dd-mmm-yy hh:nn:ss:uu"); " 
("; CFloat(SecondDate); ") Diff:"; DateDiff(firstdate, SecondDate, gb.day); " 
("; CFloat(SecondDate) - CFloat(FirstDate); ")"

  SecondDate = Date(2015, 8, 1, 11, 21, 51)
  Print "5 First:"; Format(FirstDate, "dd-mmm-yy hh:nn:ss:uu"); " ("; 
CFloat(FirstDate); ") Second:"; Format(SecondDate, "dd-mmm-yy hh:nn:ss:uu"); " 
("; CFloat(SecondDate); ") Diff:"; DateDiff(firstdate, SecondDate, gb.day); " 
("; CFloat(SecondDate) - CFloat(FirstDate); ")"

  SecondDate = Date(2015, 8, 1, 23, 59, 59.999)
  Print "6 First:"; Format(FirstDate, "dd-mmm-yy hh:nn:ss:uu"); " ("; 
CFloat(FirstDate); ") Second:"; Format(SecondDate, "dd-mmm-yy hh:nn:ss:uu"); " 
("; CFloat(SecondDate); ") Diff:"; DateDiff(firstdate, SecondDate, gb.day); " 
("; CFloat(SecondDate) - CFloat(FirstDate); ")"

  SecondDate = DateAdd(firstdate, GB.Day, 2)
  Pri

Re: [Gambas-user] datediff problem

2015-08-13 Thread Jussi Lahtinen
I think this fixes the problem (in gbx_date.c):

int DATE_diff(VALUE *date1, VALUE *date2, int period)
{
int64_t diff = 0;
int sdiff, tmpdiff;
DATE_SERIAL ds1 = {0};
DATE_SERIAL ds2 = {0};
bool neg;

switch (period)
{
case DP_DAY:
case DP_WEEK:
diff = date1->_date.date - date2->_date.date;
sdiff = lsgn(diff);
tmpdiff = lsgn(date1->_date.time - date2->_date.time);
if (sdiff != tmpdiff && tmpdiff != 0)
diff -= sdiff;
break;

case DP_MILLISECOND:
case DP_SECOND:
case DP_MINUTE:
case DP_HOUR:
diff = date1->_date.date - date2->_date.date;
diff = diff * 8640 + (date1->_date.time -
date2->_date.time);
break;

case DP_MONTH:
case DP_QUARTER:
case DP_YEAR:
ds1 = *DATE_split(date1);
ds2 = *DATE_split(date2);
break;

case DP_WEEKDAY:
diff = date1->_date.date - date2->_date.date;
sdiff = lsgn(diff);
if (sdiff != lsgn(date1->_date.time - date2->_date.time))
diff -= sdiff;
ds1 = *DATE_split(date1);
ds2 = *DATE_split(date2);
break;

default:
THROW(E_ARG);
}

switch (period)
{
case DP_DAY:
break;

case DP_WEEK:
diff /= 7;
break;

case DP_SECOND:
diff /= 1000;
break;

case DP_MINUTE:
diff /= 6;
break;

case DP_HOUR:
diff /= 360;
break;

case DP_WEEKDAY:

neg = (diff < 0);
if (neg)
{
int swap;
diff = (-diff);
swap = ds1.weekday;
ds1.weekday = ds2.weekday;
ds2.weekday = swap;
}

diff = diff / 7 * 5;

/* last day is not included ! */
while (ds2.weekday != ds1.weekday)
{
if (ds2.weekday > 0 && ds2.weekday < 6)
diff++;
ds2.weekday++;
if (ds2.weekday == 7)
ds2.weekday = 0;
}

if (neg)
diff = (-diff);

break;

case DP_MONTH:
diff = (ds1.year - ds2.year) * 12 + ds1.month - ds2.month;
break;

case DP_QUARTER:
diff = (ds1.year - ds2.year) * 4 + (ds1.month - ds2.month) / 3;
break;

case DP_YEAR:
diff = ds1.year - ds2.year;
break;

case DP_MILLISECOND:
break;
}

if (diff < INT32_MIN || diff > INT32_MAX)
THROW(E_OVERFLOW);

return diff;
}


Can someone confirm my fix to the function?


Jussi


On Thu, Aug 13, 2015 at 5:22 PM, Adrien Prokopowicz <
adrien.prokopow...@gmail.com> wrote:

> Le Mon, 10 Aug 2015 13:41:17 +0200, Jussi Lahtinen
>  a écrit:
>
> > Sorry to say, but this doesn't seem to be fixed.
> >
> > ? DateDiff(Now, DateAdd(Now, gb.Day, 2), gb.Day)
> > 1
> >
> >
> > Jussi
> >
> > On Sat, Aug 1, 2015 at 7:16 PM, Benoît Minisini <
> > gam...@users.sourceforge.net> wrote:
> >
> >> Le 01/08/2015 17:52, Benoît Minisini a écrit :
> >> > Le 01/08/2015 17:33, nando a écrit :
> >> >> Here's an example.
> >> >>
> >> >>Dim FirstDate as Date
> >> >>
> >> >>FirstDate = Date(2015, 1, 1, 0, 0, 0, 0)
> >> >>Print DateDiff(firstdate, Date(2015, 8, 1, 00, 00, 00), gb.day)
> >> 'ok
> >> >>Print DateDiff(firstdate, Date(2015, 8, 1, 00, 00, 01), gb.day)
> >> 'ok
> >> >>Print DateDiff(firstdate, Date(2015, 8, 1, 03, 59, 59), gb.day)
> >> 'ok
> >> >>Print DateDiff(firstdate, Date(2015, 8, 1, 04, 00, 00), gb.day)
> >> >> 'Wrong
> >> >>Print DateDiff(firstdate, Date(2015, 8, 1, 11, 21, 51), gb.day)
> >> >> 'Wrong
> >> >>
> >> >> 212
> >> >> 212
> >> >> 212
> >> >> 213  <---Wrong  should be 212
> >> >> 213  <---Wrong  should be 212
> >> >>
> >> >> Of course, this is looks like it might be a TimeZone problem.
> >> >> I am in GMT -5 but daylight savings during the summer it is -4
> >> >>
> >> >> Am I correct to say this is not correct operation?
> >> >>
> >> >> -Nando
> >> >>
> >> >>
> >> >
> >> > Argh, a just too late bug! You did that to spoil my holidats? 8-o
> >> >
> >>
> >> OK, I couldn't let you alone. I have updated the Gambas 3.8 source
> >> package with the fix for that bug.
> >>
> >> Regards,
> >>
> >> --
> >> Benoît Minisini
>
> That's weird, but the examples given (both jussi's and nando's) all work
> correctly before Benoît's fix (pre-7212), but not after (post-7212) !
>
> Am I missing something completely obvious, or do you get the same behavior
> ?
>
> Here's my test code :
>
> Dim FirstDate As Date
>
>  FirstDate = Date(2015, 1, 1, 0, 0, 0, 0)
>  Print DateDiff(firstdate, Date(2015, 8, 1, 00, 00, 00), gb.day)
>  Print Date