home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / developmen / oplexamp / AALARM.OPL < prev    next >
Text File  |  1993-01-21  |  2KB  |  86 lines

  1. PROC aalarm:
  2.     local r%,acb%,aactive%,astat%
  3.     local k%(2),kstat%,kactive%
  4.     local t1&,t2&,m$(20),ztsm$(22)
  5.     local dat&,tim&,atype%
  6.     local warning&
  7.     r%=ioopen(acb%,"ALM:",-1)
  8.     if r% :raise r% :endif
  9.     atype%=2
  10.     gBorder 4
  11.     busy "Any key sets alarm"
  12.     while 1
  13.         if kactive%=0
  14.             keya(kstat%,k%(1))
  15.             kactive%=1
  16.         endif
  17.         iowait
  18.         if aactive% and astat%<>-46
  19.             aactive%=0
  20.             giprint ""
  21.             busy "Any key sets alarm"
  22.             continue
  23.         endif
  24.         busy off
  25.         if k%(1)=27
  26.             giprint "Bye..."
  27.             pause -30
  28.             stop
  29.         endif
  30.         kactive%=0
  31.         if aactive%
  32.             iow(acb%,4,#0,#0)
  33.             iowaitstat astat%
  34.             aactive%=0
  35.             dInit "Edit alarm"
  36.         else
  37.             t2&=timenow&:+3600
  38.             warning&=15
  39.             m$="Don't forget!"
  40.             dInit "Set alarm"
  41.         endif
  42.         dEdit m$,"Text message"
  43.         crack:(addr(t2&),addr(dat&),addr(tim&))
  44.         dDate dat&,"Date",days(day,month,year),days(31,12,2049)
  45.         dTime tim&,"Time",0,0,datetosecs(1970,1,1,23,59,59)
  46.         dLong warning&,"Advance time",0,10080
  47.         dChoice atype%,"Alarm type","Date only,Time and date"
  48.         if dialog
  49.             t2&=combine&:(addr(dat&),addr(tim&))
  50.             t1&=t2&-warning&*60
  51.             ztsm$=m$+chr$(0)
  52.             ioa(acb%,atype%,astat%,t1&,#addr(ztsm$)+1)
  53.             aactive%=1
  54.             giprint "Alarm queued"
  55.             busy "Any key edits alarm"
  56.         else
  57.             busy "Any key sets alarm"
  58.         endif
  59.     endwh
  60. ENDP
  61.  
  62. PROC timenow&:
  63. REM returns LONG giving system time
  64.     local ax%,bx%,cx%,dx%,si%,di%,st&
  65.     ax%=$0200
  66.     os($89,addr(ax%))   rem TimGetSystemTime
  67.     pokew addr(st&),bx% :pokew addr(st&)+2,ax%
  68.     return(st&)
  69. ENDP
  70.  
  71. PROC crack:(ast%,adat%,atim%)
  72. REM cracks system time into day-sec format
  73.     local dat&,tim&
  74.     local cx%,dx%
  75.     cx%=peekw(ast%+2)
  76.     dx%=peekw(ast%)
  77.     call($0489,0,cx%,dx%,0,addr(dat&))  rem TimSystemTimeToDaySeconds
  78.     pokel adat%,dat&
  79.     pokel atim%,tim&
  80. ENDP
  81.  
  82. PROC combine&:(adat%,atim%)
  83. REM combines day-sec format into system time format
  84.     return(86400.0*(peekl(adat%)-25567.0)+peekl(atim%))
  85. ENDP
  86.