Thread View: comp.lang.modula2
2 messages
2 total messages
Started by Steve Perry
Wed, 20 Mar 1996 23:54
help on longcard
Author: Steve Perry
Date: Wed, 20 Mar 1996 23:54
Date: Wed, 20 Mar 1996 23:54
25 lines
1650 bytes
1650 bytes
I am seeking help solving a problem, I will at the outset own up to it being a homework-help problem, but would add that the answer to this does represent only a *very* small part of the task that I have to complete! Using FST Modula-2 I need to write, as a small part of an assignment, a timer that takes as a starting point the number of seconds that have elapsed since midnight. This would entail storing a value <= 86400. The GetTime procedure returns CARDINAL values for - minutes since midnight and milliseconds past the minute. I intended to use the following: MyTime := GetTime((SysTime.minutes)*60)+(SysTime.millisec)/1000)); However the result produced can be a value that requires a LONGCARD for storage. I have to date not been able to get the result into a VAR declared AS LONGCARD. I have tried LONG(..) to no avail. Have I missed something basic? A CARDINAL is stored in 2 bytes and a LONGCARD in 4 bytes so why is there not a procedure to convert? My tutor for this subject is not available for several days, none of my text books offer an answer, so any help would be much appreciated. regards -- Steve Perry email steve@suko.demon.co.uk fax By voice first please
Re: help on longcard
Author: Peter P. Eiserloh
Date: Thu, 21 Mar 1996 18:55
Date: Thu, 21 Mar 1996 18:55
53 lines
2793 bytes
2793 bytes
In article <vCnhuFASrJUxEwoQ@suko.demon.co.uk> Steve Perry, steve@suko.demon.co.uk writes: >I am seeking help solving a problem, I will at the outset own up to it >being a homework-help problem, but would add that the answer to this >does represent only a *very* small part of the task that I have to >complete! >Using FST Modula-2 I need to write, as a small part of an assignment, a >timer that takes as a starting point the number of seconds that have >elapsed since midnight. >This would entail storing a value <= 86400. >The GetTime procedure returns CARDINAL values for - minutes since >midnight and milliseconds past the minute. >I intended to use the following: >MyTime := GetTime((SysTime.minutes)*60)+(SysTime.millisec)/1000)); >However the result produced can be a value that requires a LONGCARD for >storage. >I have to date not been able to get the result into a VAR declared AS >LONGCARD. I have tried LONG(..) to no avail. >Have I missed something basic? A CARDINAL is stored in 2 bytes and a >LONGCARD in 4 bytes so why is there not a procedure to convert? >My tutor for this subject is not available for several days, none of my >text books offer an answer, so any help would be much appreciated. >regards I don't have immediate access to the FST def files, and trying to remember the peculiarities of FST, what you need is: MODULE Timer; FROM SYSTEM IMPORT LONG; PROCEDURE GetCurrentTime(VAR time : LONGCARD); (* --- Get current time in number of seconds from midnight --- *) VAR mins, millis : CARDINAL; BEGIN mins := GetMinsFromMidnight(); millis := GetMilliSecsFromMinute(); time := LONG(mins) * 60L + LONG(millis DIV 1000); END GetCurrentTime; END Timer. FST uses the non-standard suffix "L" to indicate literals which are LONG. I used the LONG() type transfer function from a hypothetical SYSTEM module. Newer compilers would do something like CAST(LONGCARD, mins). Hope this helps, all you have to do is insert the correct names for the functions which get the minutes, and milli-seconds from the OS. Peter -----
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads