Liberty BASIC Community Forum
« Glucose Diary »

Welcome Guest. Please Login or Register.
Jan 22nd, 2018, 6:04pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Glucose Diary  (Read 334 times)
johnatuna
Senior Member
ImageImageImageImage


member is offline

Avatar

Oh cool! My computer comes with a coffee cup holder!


PM

Gender: Male
Posts: 287
xx Glucose Diary
« Thread started on: Apr 16th, 2016, 6:03pm »

I wrote a program today for my fellow Diabetics out there.

Code:
'Glucose Diary Program
'Written by: John Castleberry
'2016

    dim info$(10,10)
    fpath$ = "c:\Diary\diary.dat"
    if fileExists(fpath$) then
        'do nothing
    else
        resp = mkdir("c:\Diary")
        open "c:\Diary\diary.dat" for output as #1
        close #1
    end if

   nomainwin
    WindowWidth = 775
    WindowHeight = 350
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)

    meals$(1) = "Breakfast"
    meals$(2) = "Lunch"
    meals$(3) = "Dinner"
    meals$(4) = "Snack"

    statictext #main.statictext1, "Date",   5,  12,  40,  20
    TextboxColor$ = "white"
    textbox #main.txtEntryDate,  45,   7, 110,  25
    statictext #main.statictext4, "Time",   5,  37,  40,  20
    textbox #main.txtEntryTime,  45,  37, 110,  25
    statictext #main.statictext6, "Meal",   5,  72,  35,  20
    listbox #main.lstMeal,  meals$(), [DoNothing], 45,  67, 110,  25
    statictext #main.statictext8, "Level",   5, 102,  38,  20
    textbox #main.txtGlucose,  45,  97, 110,  25
    button #main.btnSubmit,"Submit",[Submit], UL,  20, 137, 116,  25
    textbox #main.txtRecords, 165,  25, 575, 275
    Button #main.btnPrint, "Print Records", [Print], UL, 20, 182, 116, 25
    Button #main.btnPrint, "Show Records", [Update], UL, 20, 226, 116, 25
    button #main.btnQuit,"Quit",[Quit], UL,  20, 271, 116,  25
    statictext #main.statictext14, "Past Level Readings", 350,   5, 175,  20

    stylebits #main, 0,  _WS_SYSMENU, 0, 0
    open "                                                                                                                        Glucose Diary" for window as #main
    print #main, "font georgia 12"

    EntryDate$ = date$("mm/dd/yyyy")
    print #main.txtEntryDate, EntryDate$

    t$=time$()
    hrs=val(t$)
    min$=":"+right$("00"+str$(int(.5+val(word$(t$,2,":"))+val(word$(t$,3,":"))/60)),2)
    if hrs<12 then time$=str$(hrs)+min$+" AM"
    if hrs=12 then time$="12:00 PM"
    if hrs>12 then time$=" " + str$(hrs-12)+min$+" PM"
    print #main.txtEntryTime, time$
    goto [Update]
  wait

[DoNothing]
    wait

[Print]
    open "c:\Diary\diary.dat" for input as #source
    lprint "                          Glucose Meter Readings Diary"
    lprint
    while eof( #source ) = 0
    line input #source, text$
    lprint text$
    wend
    close #source
    dump
    wait

[Submit]
    print #main.txtEntryDate, "!contents? EntryDate$"

    print #main.txtEntryTime, "!contents? t$"

    print #main.lstMeal, "selection? Meal$"
    if Meal$ = "" then
    notice "Please Select a Meal!"
    wait
    end if
    Symbols$ = "<>,:;!@#$%^&*()-_=+`~"
    Meal$ = remchar$(Meal$, Symbols$)

    print #main.txtGlucose, "!contents? GlucoseLevel$"
    if GlucoseLevel$ = "" then
    notice "Please Enter Your Glucose Level for " + Meal$ + "!"
    wait
    end if
    Symbols$ = "abcdefghijklmnopqrstuvwxyz <>,:;!@#$%^&*()-_=+`~"
    GlucoseLevel$ = remchar$(GlucoseLevel$, Symbols$)

    open "c:\Diary\diary.dat" for append as #Diary
    DiaryEntry$ = "Date " + EntryDate$ + "     " + "Time " + t$ + "    " + "Glucose Level " + GlucoseLevel$ + "     " + "Meal " + Meal$
    print #Diary, DiaryEntry$
    close #Diary

    notice "Glucose Diary Entry Saved!"
    print #main.lstMeal, "selectindex "; -1
    print #main.txtGlucose, ""

[Update]
    open "c:\Diary\diary.dat" for input as #g
    txt$ = input$(#g, lof(#g))
    close #g
    print #main.txtRecords, txt$
    wait

[Quit]
      close #main
        end

function fileExists(fullPath$)
    files pathOnly$(fullPath$), filenameOnly$(fullPath$), info$()
    fileExists = val(info$(0, 0)) > 0
end function

'return just the directory path from a full file path
function pathOnly$(fullPath$)
    pathOnly$ = fullPath$
    while right$(pathOnly$, 1) <> "\" and pathOnly$ <> ""
        pathOnly$ = left$(pathOnly$, len(pathOnly$)-1)
    wend
end function

'return just the filename from a full file path
function filenameOnly$(fullPath$)
    pathLength = len(pathOnly$(fullPath$))
    filenameOnly$ = right$(fullPath$, len(fullPath$)-pathLength)
end function
wait
 
User IP Logged

Johnatuna = John at UNA(University of North Alabama)
johnatuna
Senior Member
ImageImageImageImage


member is offline

Avatar

Oh cool! My computer comes with a coffee cup holder!


PM

Gender: Male
Posts: 287
xx Re: Glucose Diary
« Reply #1 on: Apr 16th, 2016, 6:46pm »

Made a couple improvements.

Code:
'Glucose Diary Program
'Written by: John Castleberry
'2016

    on error goto [errorHandler]
    dim info$(10,10)
    fpath$ = "c:\Diary\diary.dat"
    if fileExists(fpath$) then
        'do nothing
    else
        resp = mkdir("c:\Diary")
        open "c:\Diary\diary.dat" for output as #1
        close #1
    end if

   nomainwin
    WindowWidth = 775
    WindowHeight = 350
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)

    meals$(1) = "Breakfast"
    meals$(2) = "Lunch"
    meals$(3) = "Dinner"
    meals$(4) = "Snack"

    statictext #main.statictext1, "Date",   5,  12,  40,  20
    TextboxColor$ = "white"
    textbox #main.txtEntryDate,  45,   7, 110,  25
    statictext #main.statictext4, "Time",   5,  37,  40,  20
    textbox #main.txtEntryTime,  45,  37, 110,  25
    statictext #main.statictext6, "Meal",   5,  72,  35,  20
    listbox #main.lstMeal,  meals$(), [DoNothing], 45,  67, 110,  25
    statictext #main.statictext8, "Level",   5, 102,  38,  20
    textbox #main.txtGlucose,  45,  97, 110,  25
    button #main.btnSubmit,"Submit",[Submit], UL,  20, 137, 116,  25
    textbox #main.txtRecords, 165,  25, 575, 275
    Button #main.btnPrint, "Print Records", [Print], UL, 20, 182, 116, 25
    Button #main.btnPrint, "Reset Records", [Reset], UL, 20, 226, 116, 25
    button #main.btnQuit,"Quit",[Quit], UL,  20, 271, 116,  25
    statictext #main.statictext14, "Past Level Readings", 350,   5, 175,  20

    stylebits #main, 0,  _WS_SYSMENU, 0, 0
    open "                                                                                                                        Glucose Diary" for window as #main
    print #main, "font georgia 12"

    EntryDate$ = date$("mm/dd/yyyy")
    print #main.txtEntryDate, EntryDate$

    t$=time$()
    hrs=val(t$)
    min$=":"+right$("00"+str$(int(.5+val(word$(t$,2,":"))+val(word$(t$,3,":"))/60)),2)
    if hrs<12 then time$=str$(hrs)+min$+" AM"
    if hrs=12 then time$="12:00 PM"
    if hrs>12 then time$=" " + str$(hrs-12)+min$+" PM"
    print #main.txtEntryTime, time$
    goto [Update]
  wait

[DoNothing]
    wait

[Reset]
    prompt "Are you certain you want to delete your Diary entries?"; Response$
    if Response$ = "Yes" or Response$ = "yes" then
    kill "c:\Diary\diary.dat"
    print #main.txtRecords, ""
    else
    end if
    wait

[Print]
    open "c:\Diary\diary.dat" for input as #source
    lprint "                          Glucose Meter Readings Diary"
    lprint
    while eof( #source ) = 0
    line input #source, text$
    lprint text$
    wend
    close #source
    dump
    wait

[Submit]
    print #main.txtEntryDate, "!contents? EntryDate$"

    print #main.txtEntryTime, "!contents? t$"

    print #main.lstMeal, "selection? Meal$"
    if Meal$ = "" then
    notice "Please Select a Meal!"
    wait
    end if
    Symbols$ = "<>,:;!@#$%^&*()-_=+`~"
    Meal$ = remchar$(Meal$, Symbols$)

    print #main.txtGlucose, "!contents? GlucoseLevel$"
    if GlucoseLevel$ = "" then
    notice "Please Enter Your Glucose Level for " + Meal$ + "!"
    wait
    end if
    Symbols$ = "abcdefghijklmnopqrstuvwxyz <>,:;!@#$%^&*()-_=+`~"
    GlucoseLevel$ = remchar$(GlucoseLevel$, Symbols$)

    open "c:\Diary\diary.dat" for append as #Diary
    DiaryEntry$ = "Date " + EntryDate$ + "     " + "Time " + t$ + "    " + "Glucose Level " + GlucoseLevel$ + "     " + "Meal " + Meal$
    print #Diary, DiaryEntry$
    close #Diary

    notice "Glucose Diary Entry Saved!"
    print #main.lstMeal, "selectindex "; -1
    print #main.txtGlucose, ""

[Update]
    open "c:\Diary\diary.dat" for input as #g
    txt$ = input$(#g, lof(#g))
    close #g
    print #main.txtRecords, txt$
    wait

[errorHandler]
     wait

[Quit]
      close #main
        end

function fileExists(fullPath$)
    files pathOnly$(fullPath$), filenameOnly$(fullPath$), info$()
    fileExists = val(info$(0, 0)) > 0
end function

'return just the directory path from a full file path
function pathOnly$(fullPath$)
    pathOnly$ = fullPath$
    while right$(pathOnly$, 1) <> "\" and pathOnly$ <> ""
        pathOnly$ = left$(pathOnly$, len(pathOnly$)-1)
    wend
end function

'return just the filename from a full file path
function filenameOnly$(fullPath$)
    pathLength = len(pathOnly$(fullPath$))
    filenameOnly$ = right$(fullPath$, len(fullPath$)-pathLength)
end function
wait
 
User IP Logged

Johnatuna = John at UNA(University of North Alabama)
johnatuna
Senior Member
ImageImageImageImage


member is offline

Avatar

Oh cool! My computer comes with a coffee cup holder!


PM

Gender: Male
Posts: 287
xx The final draft!
« Reply #2 on: Apr 17th, 2016, 12:23pm »

Code:
'Glucose Diary Program
'Written by: John Castleberry
'2016

    on error goto [errorHandler]

    dim info$(10,10)
    fpath$ = "c:\Diary\diary.dat"
    if fileExists(fpath$) then
        'do nothing
    else
        resp = mkdir("c:\Diary")
        open "c:\Diary\diary.dat" for output as #1
        close #1
    end if

    fpath$ = "c:\Diary\average.dat"
    if fileExists(fpath$) then
        'do nothing
    else
        resp = mkdir("c:\Diary")
        open "c:\Diary\average.dat" for output as #1
        close #1
    end if

    nomainwin
    WindowWidth = 775
    WindowHeight = 350
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)

    meals$(1) = "Breakfast"
    meals$(2) = "Lunch"
    meals$(3) = "Dinner"
    meals$(4) = "Snack"

    statictext #main.statictext1, "Date",   5,  12,  40,  20
    TextboxColor$ = "white"
    textbox #main.txtEntryDate,  45,   7, 110,  25
    statictext #main.statictext4, "Time",   5,  37,  40,  20
    textbox #main.txtEntryTime,  45,  37, 110,  25
    statictext #main.statictext6, "Meal",   5,  72,  35,  20
    listbox #main.lstMeal,  meals$(), [DoNothing], 45,  67, 110,  25
    statictext #main.statictext8, "Level",   5, 102,  38,  20
    textbox #main.txtGlucose,  45,  97, 110,  25
    button #main.btnSubmit,"Submit",[Submit], UL,  20, 137, 116,  25
    Stylebits #main.txtRecords, _WS_VSCROLL OR _ES_MULTILINE, _ES_AUTOHSCROLL, 0, 0
    textbox #main.txtRecords, 165,  25, 575, 275
    Button #main.btnPrint, "Print Records", [Print], UL, 20, 182, 116, 25
    Button #main.btnPrint, "Reset Records", [Reset], UL, 20, 226, 116, 25
    button #main.btnQuit,"Quit",[Quit], UL,  20, 271, 116,  25
    statictext #main.statictext14, "Past Level Readings", 350,   5, 175,  20
    statictext  #main.lblaverage, "Average Levels ", 550, 5, 175, 20
    stylebits #main, 0,  _WS_SYSMENU, 0, 0
    open "                                                                                                                        Glucose Diary" for window as #main
    print #main, "font georgia 12"

    EntryDate$ = date$("mm/dd/yyyy")
    print #main.txtEntryDate, EntryDate$

    t$=time$()
    hrs=val(t$)
    min$=":"+right$("00"+str$(int(.5+val(word$(t$,2,":"))+val(word$(t$,3,":"))/60)),2)
    if hrs<12 then time$=str$(hrs)+min$+" AM"
    if hrs=12 then time$="12:00 PM"
    if hrs>12 then time$=str$(hrs-12)+min$+" PM"

    print #main.txtEntryTime, time$
    goto [Update]
  wait

[DoNothing]
    wait

[Reset]
    prompt "Are you certain you want to delete your Diary?"; Response$
    if Response$ = "Yes" or Response$ = "yes" then
    kill "c:\Diary\diary.dat"
     kill "c:\Diary\average.dat"
    print #main.txtRecords, ""
    else
    end if
    wait

[Print]
    open "c:\Diary\diary.dat" for input as #source
    lprint "                          Glucose Meter Readings Diary"
    lprint
    while eof( #source ) = 0
    line input #source, text$
    lprint text$
    wend
    close #source
    dump
    wait

[Submit]
    print #main.txtEntryDate, "!contents? EntryDate$"

    print #main.txtEntryTime, "!contents? t$"

    print #main.lstMeal, "selection? Meal$"
    if Meal$ = "" then
    notice "Please Select a Meal!"
    wait
    end if
    Symbols$ = "<>,:;!@#$%^&*()-_=+`~"
    Meal$ = remchar$(Meal$, Symbols$)

    print #main.txtGlucose, "!contents? GlucoseLevel$"
    if GlucoseLevel$ = "" then
    notice "Please Enter Your Glucose Level for " + Meal$ + "!"
    wait
    end if
    Symbols$ = "abcdefghijklmnopqrstuvwxyz <>,:;!@#$%^&*()-_=+`~"
    GlucoseLevel$ = remchar$(GlucoseLevel$, Symbols$)
    GlucoseLevel = val(GlucoseLevel$)
    if len(GlucoseLevel$)  = 1 or len(GlucoseLevel$) >= 4 then
    notice "Error in Glucose Count Entry! Please Check Your Figures!"
    wait
    end if

    if len(GlucoseLevel$) < 3  and len(GlucoseLevel$) > 1 then
    i = 3 - len(GlucoseLevel$)
    GlucoseLevel$ = "  " + GlucoseLevel$
    end if

    open "c:\Diary\diary.dat" for append as #Diary
    DiaryEntry$ = "Date " + EntryDate$ + "     " + "Time " + t$ + "    " + "Glucose Level " + GlucoseLevel$ + "     " + "Meal " + Meal$
    print #Diary, DiaryEntry$
    close #Diary
    open "c:\Diary\average.dat" for append as #average
    print #average, GlucoseLevel$
    close #average

    notice "Glucose Diary Entry Saved!"
    print #main.lstMeal, "selectindex "; -1
    print #main.txtGlucose, ""

[Update]
    open "c:\Diary\diary.dat" for input as #g
    txt$ = input$(#g, lof(#g))
    close #g
    print #main.txtRecords, txt$

    Open "c:\diary\average.dat" for input as #text
[loop]
    if eof(#text) <> 0 then [EndLoop]
    counter = counter + 1
    input #text, item
    itemtotal=itemtotal+item
    goto [loop]
[EndLoop]
    average$ = using("###.#",  itemtotal/counter)
    #main.lblaverage, "Average Levels " + average$
    close #text

[errorHandler]
     wait

[Quit]
      close #main
        end

function fileExists(fullPath$)
    files pathOnly$(fullPath$), filenameOnly$(fullPath$), info$()
    fileExists = val(info$(0, 0)) > 0
end function

'return just the directory path from a full file path
function pathOnly$(fullPath$)
    pathOnly$ = fullPath$
    while right$(pathOnly$, 1) <> "\" and pathOnly$ <> ""
        pathOnly$ = left$(pathOnly$, len(pathOnly$)-1)
    wend
end function

'return just the filename from a full file path
function filenameOnly$(fullPath$)
    pathLength = len(pathOnly$(fullPath$))
    filenameOnly$ = right$(fullPath$, len(fullPath$)-pathLength)
end function
wait

function ampm$(t$)
    hrs=val(t$)
    ampm$=right$("  "+str$(hrs-12*(hrs>12))+mid$(t$,3),8)+" "+word$("PM AM",(hrs<12)+1)
end function
 
User IP Logged

Johnatuna = John at UNA(University of North Alabama)
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

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