[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 264: mysqli_fetch_assoc(): Couldn't fetch mysqli_result
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 326: mysqli_free_result(): Couldn't fetch mysqli_result
Pete's QBASIC Site Discuss QBasic, Freebasic, QB64 and more 2005-07-01T18:53:12-05:00 http://www.petesqbsite.com/phpBB3/app.php/feed/topic/629 2005-07-01T18:53:12-05:00 2005-07-01T18:53:12-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=5254#p5254 <![CDATA[Dayname]]>
Incidentally he's the author of the building in front of my office. :D

How can I be so absent-minded?

Statistics: Posted by Antoni — Fri Jul 01, 2005 6:53 pm


]]>
2005-07-01T18:12:15-05:00 2005-07-01T18:12:15-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=5253#p5253 <![CDATA[Dayname]]>
Edward:
Now I know why I called you Rafael.. Rafael Moneo is an important spanish architect: you can do a Google search for him. He is from Navarra, the region surrounding Pamplona, where the Sanfermines are hold in july 7. Have you ever felt the wish of eating 2 lbs. steaks, drinking thick red wine and running in front of bulls? :D That could be a clue about your origins...
Antoni,
In a previous post, I wrote to you in Spanish and mentioned about Rafael Moneo. I have read about him.

I didn't know he was from Navarra. I have been in Navarra a few times, and once, when I was 15, I went there to the Sanfermines. "Uno de enero, dos de febrero... siete de julio San Fermin. A Pamplona hemos de ir... con una media y un calcet?n". I was there for a week and had a wonderful time. My relatives did not let me get into the encierro and run in front of the bulls --- a wise decision.

I didn't like the 2 lb. steaks (chuletones), but the wine was great, especially from a well-cured bota or a porr?n. My origins are well defined since my father was from Bilbao. But all the Basque songs I know are at least 70 years old, like "Las Sardinitas", or "Anton, Anton, no salgas al sol", or "Un ingles vino a Bilbao".

In the USA, there's a famous Basque festival in a little town called Elko, Nevada. Every year at the beginning of July, I again wish I could go there. It's very far, about 600 miles from Las Vegas, and not near to any place else. There are lots of Basque immigrants in that area. Oh well, maybe next year.
*****

Statistics: Posted by moneo — Fri Jul 01, 2005 6:12 pm


]]>
2005-07-01T17:51:18-05:00 2005-07-01T17:51:18-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=5252#p5252 <![CDATA[Dayname]]>
Moneo:
I have found what's wrong with your date validation and FB. Here:

Code:

ZTEMP$="1"+Z$+"1"IF LEN(Z$)<>8 OR MID$(STR$(VAL(ZTEMP$)),2)<>ZTEMP$ THEN :RETURN
you rely in QB's STR$ adding a space at the front of the value returned. You know, v1ctor removed it because he hated to type ltrim$(str$()). As the compiler may rely in it, it is unlikely he changes it back.

Commenting out these lines the rest of the program works correctly in FB.
Yes, Antoni,
Several weeks ago while converting a QuickBasic program to Freebasic, I discovered that incompatibility. I wrote to v1ctor about it, and he almost bit my head off.

So now we have to do LTRIM$(STR$(X)) where we used to do MID$(STR$(X),2). It's not a big deal and is actually simpler. But, I wonder what other things v1ctor didn't like and changed???
*****

Statistics: Posted by moneo — Fri Jul 01, 2005 5:51 pm


]]>
2005-07-01T08:57:56-05:00 2005-07-01T08:57:56-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=5251#p5251 <![CDATA[Dayname]]>

Moneo:
I have found what's wrong with your date validation and FB. Here:

Code:

ZTEMP$="1"+Z$+"1"IF LEN(Z$)<>8 OR MID$(STR$(VAL(ZTEMP$)),2)<>ZTEMP$ THEN :RETURN
you rely in QB's STR$ adding a space at the front of the value returned. You know, v1ctor removed it because he hated to type ltrim$(str$()). As the compiler may rely in it, it is unlikely he changes it back.

Commenting out these lines the rest of the program works correctly in FB.

EDITED:
Edward:
Now I know why I called you Rafael.. Rafael Moneo is an important spanish architect: you can do a Google search for him. He is from Navarra, the region surrounding Pamplona, where the Sanfermines are hold in july 7. Have you ever felt the wish of eating 2 lbs. steaks, drinking thick red wine and running in front of bulls? :D That could be a clue about your origins...

Statistics: Posted by Antoni — Fri Jul 01, 2005 8:57 am


]]>
2005-07-01T06:28:44-05:00 2005-07-01T06:28:44-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=5249#p5249 <![CDATA[Dayname]]>
Well I took a look at your code, it uses the other approach, counting the days from a start day. Notice it uses too a magic number to take into account months of 30 or 31 days in compute.factor. I could not test it as your validating routine has problems with FB, it declares invalid today's date.

I will try to explain the routine I posted, no problem, the more i look at it the more surprises me.

The routine ready for FB and for QB:

Code:

FUNCTION DayName$ (Y%, M%, D%)   IF M% > 2 THEN     P% = M% - 3     Q% = Y%   ELSE     P% = M% + 9     Q% = Y% - 1   END IF   Z% = (D% + Q% + Q% \ 4 - Q% \ 100 + Q% \ 400 + CINT(2.6 * P%)) MOD 7    DayName$ = MID$("Tue Wed Thu Fri Sat Sun Mon" , 4 * Z% + 1, 3) END FUNCTION 
The idea is adding offsets (z%) from an initial day's dow. For example each non-leap year adds an offset of 1 (july 1 will be saturday next year, this is because 365 mod 7=1, and no leap years are involved)

The start day is chosen as the last day of february of the year 0, we will see why.

We start with z%=0. The day of month adds an offset equal to it's number, so we add d%
A non leap year adds 1 so we add the present year number Q% (explanation for Q% later)
Each leap year adds an additional offset of 1 so we add the count of leap years from yeat 0, this is Q% \ 4 - Q% \ 100 + Q% \ 400

Now it comes the clever part, adding the offset due to the month. We need to add an offset of 2 for every 30 days month and 3 days for a 31 day month.
To simplify the calculation we shift the start of the year to march 1, and renumber months from 0 to 11.

Code:

IF M% > 2 THEN     P% = M% - 3     Q% = Y%   ELSE     P% = M% + 9     Q% = Y% - 1 END IF
This makes march to be the month 0 of the present year and february to be the month 11 of the last year. So the shifted month number is p% and the year is q%.
Why we do this?
1.-Having february as the last month removes its singularity from the calculation of the month offset, as no date in a year is past february.
2.-We can calculate automagically the offset introduced by months with cint(2.6*p%).

Code:

month   p%  2.6*p%  cint(2.6*p%) differnce   last month  april   1    2.6      3            3         march  31 daysmay     2    5.2      5            2         april  30 daysjune    3    7.8      8            3         may    31 daysjuly    4   10.4     10            2         june   30 daysaugust  5   13       13            3         july   31 dayssept    6   15.6     16            3         aug    31 daysoct     7   18.2     18            2         sept   30 daysnov     8   20.8     21            3         oct    31 daysdec     9   23.4     23            2         nov    30 daysjan    10   26       26            3         dec    31 daysfeb    11   28.6     29            3         jan    31 days
The only thing to do is apply a modulus 7 to the total offset and use the result to index the dow table.

The table must start at the dow for that last day of february of year 0.

And that's all...The trick for the months is relly clever.


I expect this is clearer now.

Statistics: Posted by Guest — Fri Jul 01, 2005 6:28 am


]]>
2005-06-30T21:01:27-05:00 2005-06-30T21:01:27-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=5245#p5245 <![CDATA[Dayname]]> Nadie entender? porque me llamaste Rafael. F?jate que el a?o pasado en Laredo Texas, pregunt? en la recepci?n del hotel si hab?a alg?n recado para Moneo. Me respondi? el empleado "?Cual Moneo, tenemos un Edward Moneo y un Rafael Moneo". Resulta que el famoso Rafael estaba asistiendo a una conferencia. Quise conocerlo, pero como andabamos de negocios, no tuve tiempo para darme el gusto. Nunca he conocido un Moneo que no sea de mi familia inmediata.

Ok, back to the day of the week subject. Below please see the program that I put together with code from my date utility. You can see that the main subroutine DATE.FACTOR was designed to do other things as well.

The code most closely related to yours is in the subroutines COMPUTE.FACTOR and COMPUTE.WEEKDAY. I also don't fully understand the logic of COMPUTE.FACTOR which I got from my TI calculator manual 20 years ago. It's never failed.

BTW, thanks for the explanation of the code you submitted. To be perfectly honest, I still don't understand it, but thanks anyway.

Saludos,
Moneo

Code:

defint a-zDECLARE FUNCTION IsLeapYear% (Z)  DIM YEAR.MIN     AS INTEGER  'Minimum valid year for dates (default=0)DIM DATE.FACTOR  AS SINGLE   'Number of days given date is from day zero.DIM WEEK.DAY     AS INTEGER  'Day of week value: 1=Sunday....7=Saturday.DIM WEEK.NUM     AS INTEGER  'Week number within year (1 to 54).DIM JULIAN.DAY   AS INTEGER  'Day  number within year (1 to 366).DIM DATE.OK      AS INTEGER  'Valid date indicator: -1=True, 0=False.DIM ZYY          AS INTEGER  'Value of the 4 digit year.DIM ZMM          AS INTEGER  'Value of the 2 digit month.DIM ZDD          AS INTEGER  'Value of the 2 digit day.DIM ZDWORK       AS LONG     'Variable, internal to date routines.DIM ZFSAVE       AS SINGLE   'Variable, internal to date routines.DIM ZFSAVE2      AS SINGLE   'Variable, internal to date routines.DIM ZMO(1 TO 12) AS INTEGERDATA 31,28,31,30,31,30,31,31,30,31,30,31FOR ZMM=1 TO 12:READ ZMO(ZMM):NEXTREM ***************************************************************************print "Enter a date as YYYYMMDD ";input YYYYMMDD$z$=YYYYMMDD$gosub date.factorif not(date.ok) then print YYYYMMDD$;" is an invalid date":systemDayWeek$=mid$("SunMonTueWedThuFriSat",3*WEEK.DAY-2,3)print DayWeek$systemREM ***************************************************************************REM *****   S U B R O U T I N E S   REM ***************************************************************************REM *REM *** DATE.FACTOR: PRINCIPAL DATE SUBROUTINE:REM *   ======================================REM *   - Validate input date string.REM *   - Compute number of days (date.factor) from year 0, month 0, day 0.REM *   - Compute day of week.REM *   - Compute week number.REM *   - Compute "julian" day of year.REM *   - Compute date of Easter Sunday for given year. (removed)REM *REM *  INPUT: REM *  =====REM *  Z$         = Date string formatted as YYYYMMDD.REM *  YEAR.MIN   = Minimum year user wishes to allow (default 0)REM *REM * OUTPUT:REM * ======REM * DATE.OK       = -1 if input date VALID.   (true)REM *               =  0 if Input date INVALID. (false)                    REM * NOTE: IF VALID,   THE FOLLOWING VARIABLES AR BASED ON INPUT DATE.REM *       IF INVALID, THE VALUES MAY HAVE CHANGED AND ARE MEANINGLESS.REM * DATE.FACTOR   = Number of cumulative days from year/month/day 0.REM * WEEK.DAY      = 1 to   7 is Sunday to Saturday respectively.   REM * WEEK.NUM      = 1 TO  54 is week number within year.            REM * JULIAN.DAY    = 1 TO 366 is day  number within year.            REM * ZYY           = Value of of 4 digit year.        REM * ZMM           = Value of month.                    REM * ZDD           = Value of day.                                 REM * EASTERSUNDAY$ = Date of Easter for given year.                REM * Z$            = (unchanged).REM * YEAR.MIN      = (unchanged).REM *REM *REM * Date factor logic adopted from a Texas Instruments calculator manual.REM *DATE.FACTOR:  gosub Date.Check                     'check input date  if not(date.ok) then RETURN          'exit if invalid   zmm=1:zdd=1                          'set to January 1st  gosub Compute.Factor                 'compute factor of Jan 1st  zfsave=date.factor                   'save factor   of Jan 1st  gosub Compute.Weekday                'week.day now has day of week of Jan 1st  zdd=val(right$(z$,2))                'Restore input date's day + month    zmm=val(mid$(z$,5,2))     gosub Compute.Factor                 'compute factor of input date  '* Julian day is input date minus Jan 1st of same year +1  julian.day=date.factor-zfsave+1     '* Compute the week number: (week.day-1 is week day of Jan 1st relative to 0)  week.num=int((julian.day+(week.day-1)-1)/7)+1  '* Compute the day of the week of input date:  gosub Compute.WeekdayRETURNCOMPUTE.FACTOR:  DATE.FACTOR=365!*ZYY+ZDD+31*(ZMM-1)  'NOTE: WON'T WORK WITHOUT ! AFTER 365.  IF ZMM<3 THEN     DATE.FACTOR=DATE.FACTOR+INT((ZYY-1)/4)-INT(3/4*(INT((ZYY-1)/100)+1))   ELSE     DATE.FACTOR=DATE.FACTOR-INT(.4*ZMM+2.3)+INT(ZYY/4)-INT(3/4*(INT(ZYY/100)+1))  END IFRETURNCOMPUTE.WEEKDAY:  '* Compute the day of the week:  WEEK.DAY=DATE.FACTOR-INT(DATE.FACTOR/7)*7    'Modulo 7.  IF WEEK.DAY=0 THEN WEEK.DAY=7                'WEEK.DAY=1=Sunday.RETURNREM ***************************************************************************REM *********************  DATE.CHECK  ****************************************REM *REM *** VALIDATE A DATE IN YYYYMMDD FORMAT.REM *REM *  INPUT: Z$       = Given date in format YYYYMMDD.REM *         YEAR.MIN = Minimum valid year allowed. (default=0)REM *REM * OUTPUT: DATE.OK = -1 if input date is VALID.   (true)REM *                    0 if input date is INVALID. (false)                    REM *         (if VALID):REM *         ZYY      = Value of 4 digit year.        REM *         ZMM      = Value of month.                               REM *         ZDD      = Value of day.                                 REM *REM *DATE.CHECK:  DATE.OK = 0      'preset to false  ZTEMP$="1"+Z$+"1"  IF LEN(Z$)<>8 OR MID$(STR$(VAL(ZTEMP$)),2)<>ZTEMP$ THEN RETURN  ZDD=VAL(RIGHT$(Z$,2))                'Set day                  ZMM=VAL(MID$(Z$,5,2))                'Set month.  ZYY=VAL(LEFT$(Z$,4))                 'Set year.  IF ZMM<1 OR ZMM>12 OR ZDD<1 OR ZDD>31 OR ZYY<YEAR.MIN THEN RETURN  IF ZMO(ZMM)+1*(-(ZMM=2 AND ISLEAPYEAR(ZYY))) < ZDD THEN RETURN  '   If expression (month=2 and is leapyear) is TRUE which is -1, then  '   taking the negative of this issues a plus 1. Conversely, the FALSE       '   always gives a zero. Multiplying the +1 by this result of 1 or 0  '   will either add 1 or not to the number of days in the month.  '   The routine wants to add 1 only when it is February and leap year.  DATE.OK = -1        '-1=valid (true)RETURN      REM ***************************************************************************END' ====================== ISLEAPYEAR =========================='         Determines if a year is a leap year or not.' ============================================================'FUNCTION IsLeapYear (Z) STATIC   ' If the year is evenly divisible by 4 and not divisible   ' by 100, or if the year is evenly divisible by 400, then   ' it's a leap year:   IsLeapYear = (Z MOD 4 = 0 AND Z MOD 100 <> 0) OR (Z MOD 400 = 0)END FUNCTION
*****

Statistics: Posted by moneo — Thu Jun 30, 2005 9:01 pm


]]>
2005-06-30T16:00:57-05:00 2005-06-30T16:00:57-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=5239#p5239 <![CDATA[Dayname]]>
First of all my excuses for not including a big DEFINT A-Z at the top of the code. I tested it in FB where variables are integer by default. In QB it will not work unless the DEFINT is there...

I'm afraid I will have a hard time explaining the algorithm as I just found it in the ABC packets, tested it a little and posted it here for Seb.

Let's try...

The first part with the IFs make years start in march and end in february, thus making the aditional day in leap years the last day of year, so you remove the irregular february in the calculation of month offset(smart!)..

If you integer-divide 365 by 7 you have a remainder of 1, meaning if there were no leap years, each year would start 1 dow later than previous year.
So we add to the day the year number, then add the adittional days to account for leap years. The 2.6*month is approximately 31/12, it adds the offset for the months. The provision for 31 and 30 day months I guess is made in the rounding (SMART!!!!!) ...

Then the dow table starts at Tuesday, I guess it is the dow for an hypotetical (gregorian) march-1-0

Just guessing...I spent half an hour writing this while searching the net for an explanation ready to cut and paste,and found nothing.

What is your personal formula like?

Statistics: Posted by Antoni — Thu Jun 30, 2005 4:00 pm


]]>
2005-06-29T20:07:14-05:00 2005-06-29T20:07:14-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=5224#p5224 <![CDATA[Dayname]]>

***** ANTONI:

Sorry, I made an error reading the year, month, day variables. :oops:

The dates 2000,01,01 and 2000,02,29 and 2000,12,31 are correct.

EDIT: I wrote a little test program to allow checking the resultant day of the week of your logic against the results from a personal date program that I've been using for 10 years. You will be pleased to know that in a test of all the days from 1583 to 2501 the days of the week were exactly the same! :D

Could you explain your algorithm, please.


***** MYSTIKSHADOWS:

I get the wrong day of the week for any date I try, even today's date. Maybe there's a typo when you copied the code to the post.

*****

Statistics: Posted by moneo — Wed Jun 29, 2005 8:07 pm


]]>
2005-06-29T20:04:34-05:00 2005-06-29T20:04:34-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=5223#p5223 <![CDATA[Dayname]]> *****

Statistics: Posted by Guest — Wed Jun 29, 2005 8:04 pm


]]>
2005-06-29T20:00:20-05:00 2005-06-29T20:00:20-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=5222#p5222 <![CDATA[Dayname]]>
I have found a simpler routine...

Code:

FUNCTION DayName$ (Y, M, D)   IF M > 2 THEN     P = M - 3     Q = Y   ELSE     P = M + 9     Q = Y - 1   END IF   Z = (D + Q + Q \ 4 - Q \ 100 + Q \ 400 + CINT(2.6 * P)) MOD 7    DayName$ = MID$("Tue Wed Thu Fri Sat Sun Mon" , 4 * Z + 1, 3)END FUNCTION
Estimado Antoni,

If I had some kind of comments or documentation on your function, then maybe I could figure out why it doesn't work.
Examples:
For 2000,01,01 it says Wed, when it should be Sat
For 2000,02,29 it says Wed, when it should be Tue
For 2000,12,31 it says Mon, when it should be Sun

I picked the year 2000 because it has the characteristic of being a leap year because it's a multiple of 400.

Some other dates also gave me errors.
*****

Statistics: Posted by Guest — Wed Jun 29, 2005 8:00 pm


]]>
2005-06-19T17:04:42-05:00 2005-06-19T17:04:42-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=5023#p5023 <![CDATA[Dayname]]>
grtz

Statistics: Posted by Guest — Sun Jun 19, 2005 5:04 pm


]]>
2005-06-19T11:54:09-05:00 2005-06-19T11:54:09-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=5022#p5022 <![CDATA[Dayname]]>

Code:

FUNCTION DayName$ (Y, M, D)   IF M > 2 THEN     P = M - 3     Q = Y   ELSE     P = M + 9     Q = Y - 1   END IF   Z = (D + Q + Q \ 4 - Q \ 100 + Q \ 400 + CINT(2.6 * P)) MOD 7    DayName$ = MID$("Tue Wed Thu Fri Sat Sun Mon" , 4 * Z + 1, 3)END FUNCTION

Statistics: Posted by Antoni — Sun Jun 19, 2005 11:54 am


]]>
2005-06-16T05:10:29-05:00 2005-06-16T05:10:29-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=4967#p4967 <![CDATA[Dayname]]>
grtz

Statistics: Posted by Guest — Thu Jun 16, 2005 5:10 am


]]>
2005-06-15T14:48:48-05:00 2005-06-15T14:48:48-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=4959#p4959 <![CDATA[Dayname]]>
The algorithm for julian date was posted by Egbert Zijlema to the ABC packets back in 1996. The rest is mine

Julian dates linealize the calender and make easy to calculate for example the nr of days between two dates..

Code:

declare function dow$(y%,m%,d%)declare Function tojulian&(y%,M%,D%) print dow$(2005,6,15)sleepfunction dow$(y%,m%,d%)  a&=tojulian&(y%,M%,d%) dow$=mid$("Mon Tue Wed Thu Fri Sat Sun",(a& mod 7)*4+1,3)end functionFunction tojulian&(y%,M%,D%)   temp& = (M% - 14) \ 12  JulPart& = D% - 32075 + (1461 * (Y% + 4800 + temp&) \ 4)  JulPart& = JulPart& + (367 * (M% - 2 - temp& * 12) \ 12)  tojulian& = JulPart& - (3 * ((Y% + 4900 + temp&) \ 100) \ 4)end function 

Statistics: Posted by Guest — Wed Jun 15, 2005 2:48 pm


]]>
2005-06-11T02:15:21-05:00 2005-06-11T02:15:21-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=4869#p4869 <![CDATA[Dayname]]>
Does the Year% have to contain 2 or 4 digits?
Cause using 4 digits, gives me always a Sunday...
Using 2 digits... gives me... erm not the day I need...

grtz
Seb

Statistics: Posted by Guest — Sat Jun 11, 2005 2:15 am


]]>