Board Logo
« Reminder Program »

Welcome Guest. Please Login or Register.
Feb 25th, 2018, 7:58pm


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Please use the forums Search feature before asking.
Please post code using the code box described in Format Your Messages.
This will keep indentation, separate it better form the message and prevent gibberish.
If the code is too long for one post or additional files are needed, upload a ZIP archive to the Just BASIC Files Archive Site.

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Reminder Program  (Read 86 times)
AltBas
Full Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 464
xx Reminder Program
« Thread started on: Feb 9th, 2018, 2:50pm »

Here's a minimally featured program to remind you of things that need to be done - like we need help with that...
Code:
'*** Hey!.Jb - Reminder Program ***
  '* Data file is in the same folder as the executable *
  '* Or with JBasic.exe if running in IDE *

  dim R$(255)   '* Records - Lazy DIM to max # of records *
  dim Rec$(255) '* Display Records for ListBox *
  dim F$(9,9)   '* For FileExist function *
  dim Y$(10), M$(12), D$(0)  '* For Calender dialog ListBoxes *

  GLOBAL gFile$  '* Drive:Folder\FileName *
  GLOBAL gToday  '* Serial Number of today *
  GLOBAL kMon$   '* Names *
  GLOBAL kMinYr  '* Can't go to any previous years *
  GLOBAL gRecCnt '* Total number of records *
  GLOBAL kLF$    '* LineFeed char for NOTICE msgs *
  GLOBAL kPrgNm$ '* Title for NOTICE msgs *

  kMon$ = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
  kLF$ = chr$(13)
  kPrgNm$ = "Hey!" + kLF$

  gToday = date$("days")
  T$ = date$(gToday)
  kMinYr = val(right$(T$, 4))
  for a = 1 to 10 : Y$(a) = str$(kMinYr + a - 1) : next
  for a = 1 to 12 : M$(a) = word$(kMon$, a) : next

  call Init

  WindowWidth = 1000
  WindowHeight = 390
  LISTBOX #hey.lRem Rec$(), [Click], 10, 10, 970, 300
  BUTTON #hey.bQuit "Quit", [Done], UL, 10, 320, 40, 25
  BUTTON #hey.bNew "New", [New], UL, 70, 320, 40, 25
  BUTTON #hey.bEdit "Edit", [Edit], UL, 130, 320, 40, 25
  BUTTON #hey.bDel "Delete", [Del], UL, 200, 320, 60, 25
  BUTTON #hey.bAbrt "Abort", [Abort], UL, 300, 320, 60, 25

  open "Hey! Reminders" for window as #hey
  #hey "trapclose [Done]"
  #hey.lRem "singleclickselect"
  #hey.lRem "font courier_new 10"
  wait

[Done]
  for a = len(gFile$) to 1 step -1  '* Scan back from end for period *
    if mid$(gFile$, a, 1) = "." then
      Buf$ = PackRec$()
      BakFile$ = left$(gFile$, a) + "bak"
      if FileExist( BakFile$ ) then kill BakFile$  '* Back up current file *
      if FileExist( gFile$ ) then name gFile$ as BakFile$
      open gFile$ for output as #1  '* Make new file *
      print #1, Buf$;  '* Suppress Cr/Lf *
      CLOSE #1
      exit for
    end if
  next a

  call Show

[Abort]  '* Don't save changes *
  CLOSE #hey

END

[New]
  if gRecCnt >= 255 then
    NOTICE kPrgNm$ + "Limit of 255 Reminders reached!" + kLF$ +_
      "You must delete some Reminders!"
    wait
  end if
  R$ = GetRecord$( 0 )
  if R$ > "" then
    gRecCnt = gRecCnt + 1
    R$(gRecCnt) = R$
    Rec$(gRecCnt) = FormatRecord$( R$ )
    #hey.lRem "reload"
  end if
  wait

[Edit]
  if gRecCnt = 0 then wait
  if CurRec = 0 then NOTICE kPrgNm$ + "Select a Reminder first" : wait
  R$ = GetRecord$( CurRec )
  if R$ > "" then
    R$(CurRec) = R$
    Rec$(CurRec) = FormatRecord$( R$ )
    #hey.lRem "reload"
  end if
  wait

[Del]
  if gRecCnt = 0 then wait
  if CurRec = 0 then NOTICE kPrgNm$ + "Select a Reminder first" : wait
  for a = CurRec + 1 to gRecCnt
    R$(a - 1) = R$(a)
    Rec$(a - 1) = Rec$(a)
  next a
  R$(gRecCnt) = ""
  Rec$(gRecCnt) = ""
  gRecCnt = gRecCnt - 1
  #hey.lRem "reload"
  wait

[Click]
  #hey.lRem "selectionindex? CurRec"
  wait

'
'*** Display Reminders ***
'
SUB Show
  '* Show Reminders using TextEditor boxes *
  WindowWidth = 930
  WindowHeight = 550
  STATICTEXT #dsp.s1 "Items Tommorrow or Past", 10, 1, 600, 28
  TEXTEDITOR #dsp.eNow 10, 30, 900, 100
  STATICTEXT #dsp.s2 "Items in 5 Days", 10, 140, 600, 28
  TEXTEDITOR #dsp.e5D 10, 170, 900, 100
  STATICTEXT #dsp.s3 "Items Soon", 10, 290, 600, 28
  TEXTEDITOR #dsp.eSoon 10, 320, 900, 100
  BUTTON #dsp.bDone "Close", [Done], UL, 430, 440, 60, 30
  open "Reminders" for window as #dsp
  #dsp "trapclose [Done]"
  for a = 1 to gRecCnt
    R$ = left$(Rec$(a), 11) + " " + mid$(Rec$(a), instr(Rec$(a), "|", 14) + 1)
    t = asc(left$(R$(a), 1)) + (256 * asc(mid$(R$(a), 2, 1))) - gToday
    if t < 2 then #dsp.eNow R$
    if t > 1 and t < 6 then #dsp.e5D R$
    if t > 5 and t <= asc(mid$(R$(a), 3, 1)) then #dsp.eSoon R$
  next a
  wait
[Done]
  CLOSE #dsp
END SUB

'
'*** Read Data, etc... ***
'
SUB Init
  D$ = DefaultDir$
  if right$(D$, 1) <> "\" then D$ = D$ + "\"
  gFile$ = D$ + "Hey!.dat"
  eq = FileExist( gFile$ )
  if eq then
    open gFile$ for input as #1
    bl = LOF(#1)
    Buf$ = input$(#1, bl)
    CLOSE #1
    dt = asc(left$(Buf$, 1)) + (256 * asc(mid$(Buf$, 2, 1)))  '* Write date *
    tl = asc(mid$(Buf$, 3, 1)) + (256 * asc(mid$(Buf$, 4, 1))) '* True len *
    call UnPackRec  mid$(Buf$, 5, tl)
  end if
END SUB

FUNCTION PackRec$()
  for a = 1 to gRecCnt
    L$ = chr$(len(R$(a))) + R$(a)  '* Max len reminder text is ~250 char *
    Buf$ = Buf$ + L$
  next a
  t = date$("days")
  T$ = chr$(t AND 255) + chr$(int(t / 256))
  t = len(Buf$) + 1
  L$ = chr$(t AND 255) + chr$(int(t / 256))
  PackRec$ = T$ + L$ + chr$(gRecCnt) + Buf$  '* Limit 255 records *
END FUNCTION

Sub UnPackRec  Buf$
  gRecCnt = asc(left$(Buf$, 1))
  redim R$(255)
  redim Rec$(255)
  p = 2
  for a = 1 to gRecCnt
    dl = asc(mid$(Buf$, p, 1))
    R$(a) = mid$(Buf$, p+1, dl)
    Rec$(a) = FormatRecord$( R$(a) )
    p = p + dl + 1
  next a
END SUB

'
'*** Format the Display Text of the Reminder ***
'
FUNCTION FormatRecord$( R$ )
  dt = asc(mid$(R$, 1, 1)) + (256 * asc(mid$(R$, 2, 1)))
  FormatRecord$ = date$(dt) + " | " + using("##", asc(mid$(R$, 3, 1))) + _
    " days | " + mid$(R$, 4)
END FUNCTION

FUNCTION FileExist( F$ )
  FILES "", F$, F$()
  FileExist = val(F$(0,0))
END FUNCTION

'
'*** Calender Dialog ***
'
FUNCTION Calender( dt )
  DW$ = "Sun Mon Tue Wed Thu Fri Sat"
  if dt > 0 then
    T$ = date$(dt)
  else
    T$ = date$("mm/dd/yyyy")
  end if
  m = val(left$(T$, 2))  '* Date to select on calender *
  d = val(mid$(T$, 4, 2))
  y = val(right$(T$, 4))
  WindowWidth = 235
  WindowHeight = 230
  LISTBOX #Cal.lYr, Y$(), [PickYear], 10, 10, 60, 150
  LISTBOX #Cal.lMn, M$(), [PickMon], 80, 10, 60, 150
  LISTBOX #Cal.lDy, D$(), [PickDay], 150, 10, 70, 150
  BUTTON #Cal.bDone "Done", [Done], UL, 20, 170, 60, 25
  BUTTON #Cal.bCncl "Cancel", [Cancel], UL, 130, 170, 60, 25

  open "Calender" for dialog_nf_modal as #Cal
  #Cal "trapclose [Done]"

  #Cal.lYr, "singleclickselect"
  #Cal.lMn, "singleclickselect"
  #Cal.lDy, "singleclickselect"
  gosub [DayList]
  t = (y - kMinYr) + 1
  #Cal.lYr "selectindex "; t
  #Cal.lMn "selectindex "; m
  #Cal.lDy "selectindex "; d

  wait

[Cancel]
  m = -1

[Done]
  CLOSE #Cal
  if m > -1 then Calender = date$(str$(m) +"/"+ str$(d) +"/"+ str$(y))

EXIT FUNCTION
[PickYear]
  #Cal.lYr "selectionindex? t"
  if t > 0 then
    y = val(Y$(t))
    gosub [DayList]
  end if
  wait
[PickMon]
  #Cal.lMn "selectionindex? t"
  if t > 0 then
    m = t
    gosub [DayList]
  end if
  wait
[PickDay]
  #Cal.lDy "selectionindex? t"
  if t > 0 then d = t
  wait
[DayList]
  t = 32
  DO
    t = t - 1  '* Lazy - Let JB tell me if date is good :) *
    z = date$(str$(m)+"/"+str$(t)+"/"+str$(y))
  LOOP while z = 0
  redim D$(t)
  td = date$(str$(m)+"/01/"+str$(y))
  for a = 1 to t
    D$(a) = right$("0" + str$(a), 2) + "  " + word$(DW$, ((td + 2) MOD 7) + 1)
    td = td + 1
  next
  #Cal.lDy "reload"
  if d = 0 or d > t then d = 1
  #Cal.lDy "selectindex "; d  '* Re-select selected day *
  RETURN
END FUNCTION

'
'*** New or Edit Record ***
'
FUNCTION GetRecord$( Rec )
  T$ = "New"
  if Rec > 0 then
    T$ = "Edit"
    Rmd$ = mid$(R$(Rec), 4)
    Dys$ = str$(asc(mid$(R$(Rec), 3, 1)))
    Dt$ = date$(asc(left$(R$(Rec), 1)) + (256 * asc(mid$(R$(Rec), 2, 1))))
  end if
  WindowWidth = 770
  WindowHeight = 160
  TEXTBOX #rec.tRem 10, 10, 650, 25
  STATICTEXT #rec "Reminder Text", 670, 10, 120, 25
  TEXTBOX #rec.tDate 10, 40, 100, 25
  BUTTON #rec.bDate "Calender", [GetDate], UL, 120, 40, 65, 25
  STATICTEXT #rec "Date of Reminder", 200, 40, 130, 25
  TEXTBOX #rec.tDays 340, 40, 35, 25
  STATICTEXT #rec "Number of Days from today (eg, refill)", 380, 40, 320, 25
  TEXTBOX #rec.tWarn 10, 70, 40, 25
  STATICTEXT #rec "Number of days in advance to first notify", 60, 70, 600, 25
  BUTTON #rec.bOK "Done", [Save], UL, 20, 100, 50, 25
  BUTTON #rec.bOK "Cancel", [Done], UL, 680, 100, 60, 25

  open "Hey! " + T$ + " Reminder" for dialog_nf_modal as #rec
  #rec "trapclose [Done]"
  #rec.tRem "!setfocus"
  #rec.tRem Rmd$
  #rec.tWarn Dys$
  #rec.tDate Dt$
  wait

[GetDate]
  td = Calender( dt )
  #rec.tDate date$(td)
  wait

[Save]
  #rec.tRem "!contents? Rmd$"  '* Allows empty Reminder text *
  Rmd$ = left$(Rmd$, 250)  '* Sorry - Maximum length string due to file format *
  #rec.tWarn "!contents? Dys$"
  #rec.tDays "!contents? Dt$"
  if trim$(Dt$) > "" then  '* # of days takes precedence over calender *
    t = gToday + val(Dt$)
    Dt$ = date$(t)
  else
    #rec.tDate "!contents? Dt$"
  end if
  if trim$(Dt$) > "" then
    t = date$(Dt$)
    GetRecord$ = chr$(t AND 255) + chr$(int(t / 256)) + chr$(val(Dys$)) + Rmd$
  end if

[Done]
  CLOSE #rec
END FUNCTION
 

Too bad it can't (easily) have different background window colors as my old DOS version. Would have to count number of items in each class to size graphics boxes to show all reminders. Hard to do in 10000 chars...

Update 2018-02-23: Added day of week to calender day, specify number of days until reminder.

- AltBas
« Last Edit: Feb 23rd, 2018, 11:14am by AltBas » User IP Logged

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1273
xx Re: Reminder Program
« Reply #1 on: Feb 9th, 2018, 2:55pm »

Cool idea! pack it with features like spell check or Google lookup or File Manager and build your own private secretary.
User IP Logged

B+
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls