Microsoft KB Archive/37312

= Example of Toolbox Register ROM Call for Date/Time Conversion =

Article ID: 37312

Article Last Modified on 10/20/2003

-

APPLIES TO


 * Microsoft QuickBasic Compiler for Macintosh 1.0
 * Microsoft QuickBasic Compiler for Macintosh 1.0
 * Microsoft QuickBasic Compiler for Macintosh 1.0

-



This article was previously published under Q37312



SUMMARY
This article provides an example of calling Macintosh register-based ROM functions with the ToolBox statement in QuickBasic versions 1.0, 1.0a, and 1.0b for the Apple Macintosh.

This article discusses date and time conversion functions, which are register-based ROM calls accessible with the QuickBasic Toolbox statement. The following register-based ROM calls pass arguments in Macintosh machine registers:


 * The Date2Secs ROM function

This function takes a given date/time record, (a0&), which is the pointer to the date/time record, and converts it to the corresponding seconds since midnight of January 1, 1904. The result is put in the argument (d0&). The dayofweek field can be ignored for this function. See code example 1 below.
 * The Secs2Date ROM function

This function takes the number of seconds since midnight, January 1, 1904, (d0&) and converts it to the corresponding date and time, returning it in the date/time record argument, (a0&), which is the pointer to the date/time record. See code example 2 below.

Note: Further below are examples of how to use the date and time conversion functions listed above.



MORE INFORMATION
You can access Date2Secs and Secs2Date from within a QuickBasic program with the ToolBox statement. The ToolBox statement must first be initialized (only once within a program) with the following statement: ToolBox &quot;i&quot;  'case is not significant You can make a register-based ROM call in the following manner ToolBox &quot;R&quot;,trapnum%,returnarray&(0),(a0&),(a1&),(d0&),(d1&),(d2&) where the following is true:

&quot;R&quot; -- is for &quot;register call.&quot;

trapnum% -- is the trap number for the ROM routine.

returnarray&(0) -- will contain the contents of the registers a0&, a1&, d0&, d1&, d2& (in order) after the ROM call. This array must be dimensioned to five elememts.

The arguments a0&, a1&, d0&, d1&, d2& are arguments whose values are passed into the registers before the ROM call.

Note: The arguments and returnarray&(0) are optional. They depend upon whether you need to use a particular register and whether there is a return value.

The Date2Secs and Secs2Date functions use the following date/time record structure (based in Pascal): TYPE DateTimeRec = year:      integer; {1904 to 2040} month:     integer; {1 to 12 for January to December} day:       integer; {1 to 31} hour:      integer; {0 to 23)         minute:     integer; {0 to 59}         second:     integer; {0 to 59}         dayofweek:  integer; {1 to 7 for Sunday to Saturday}   END; In Basic, use an integer array to represent this structure, as in the following example:   DIM DateTimeRec%(6) where:   DateTimeRec%(0) represents DateTimeRec.year   DateTimeRec%(1) represents DateTimeRec.month   DateTimeRec%(2) represents DateTimeRec.day   DateTimeRec%(3) represents DateTimeRec.hour   DateTimeRec%(4) represents DateTimeRec.minute   DateTimeRec%(5) represents DateTimeRec.second   DateTimeRec%(6) represents DateTimeRec.dayofweek For additional information, see sections E.10.3 to E.10.3.5 of the &quot;Microsoft QuickBASIC for the Apple Macintosh: Language Reference.&quot;

See &quot;Inside Macintosh Volume II&quot; for trap numbers and descriptions of routines.

Code Example 1
Toolbox &quot;i&quot; ' Required to initialized toolbox routines; if you ' forget this statement, you get &quot;Invalid Function Call&quot; ' Example of invoking Date2Secs function. DIM returnarray&(5)  'Must be at least 5 to handle the 'five arguments for register ROM calls. DIM DateTimeRec%(6)   'set up date/time record trapnum% = &HA9C7   'trapnum for Date2Secs function d0& = 0        'initialization DateTimeRec%(0) = 1904   'fill date/time record DateTimeRec%(1) = 1 DateTimeRec%(2) = 1 DateTimeRec%(3) = 2 DateTimeRec%(4) = 46 DateTimeRec%(5) = 40 DateTimeRec%(6) = 6 ToolBox &quot;R&quot;,trapnum%,returnarray&(0),DateTimeRec%(0) ' Note: The only parameter needed is DateTimeRec%, which is passed '      through the a0& register as noted by its position. PRINT returnarray&(2), &quot;seconds have elapsed since 01-01-04&quot; The code example above gives the following output:

10000 minutes have elapsed since midnight 01-01-04

Code Example 2
' Secs2Date function example: DIM datetimerec%(6) trapnum% = &HA9C6  'trap number for Secs2Date d0& = 10000      'time in seconds ToolBox &quot;i&quot; a0& = VARPTR(datetimerec%(0)) ToolBox &quot;R&quot;,trapnum%,,(a0&),,(d0&) ' NOTE: since no return value is needed, returnarray%(0) is omitted. PRINT &quot;the year is &quot;;datetimerec%(0) PRINT &quot;month &quot;;datetimerec%(1); &quot; of the year&quot; PRINT &quot;day &quot;;datetimerec%(2); &quot; of the month&quot; PRINT &quot;the time is &quot;;datetimerec%(3);&quot; hours &quot;; datetimerec%(4); PRINT &quot; minutes &quot;;datetimerec%(5);&quot; seconds military time&quot; PRINT &quot;this is day &quot;;datetimerec%(6); &quot; in the week&quot; The code example above gives the following output:

the year is 1904

month 1 of the year

day 1 of the month

the time is 2 hundred hours 46 minutes 40 seconds military time

this is day 6 in the week

Additional query words: MQuickB 1.00 1.00a 1.00b

Keywords: KB37312

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.