Glycemic Index Database for Diabetics (Creative Commons)
Dec 3, 2020 19:45:42 GMT -5
rasser likes this
Post by donnybowers on Dec 3, 2020 19:45:42 GMT -5
This is a functioning program for collecting data about the Glycemic Index of foods. I want to make it so that you can cursor through the LISTBOX and hit enter to open the data into the form, but I don't want to sacrifice the MENU items. If anyone can show me a way to do this I would be very grateful. I intend to add a lot of MENU items, most of which will be for quick internet searches for the user to do research for their diet.
I recently found out I have diabetes and that prompted me to start work on this project. It's open source, so you can use the code for your own version and publish it under the license terms if you want to. I'm sure this program can be modified for use with something else besides the Glycemic Index. I intend to add more fields to for collecting all the info about carbs (fiber, sugar, etc.). Right now it only has total carbs.
I've tried this with both Just BASIC and Liberty BASIC in Linux Wine and in a Windows XP virtual machine. Let me know if there are any issues. Future posts of this code may be linked to a page at my website; as the code will probably get too big to post here.
The item in the "Search" menu will search the internet for the Glycemic Index of whatever food name you put in the first field at the top right of the screen, which is not labeled, but is the "food name" field. And when you save, the program automatically calculates the Glycemic Load for you as long as you have entered the Glycemic Index and the amount of carbs in a serving. You can learn how these numbers are helpful in your diet by googling "glycemic index" and "glycemic load". It's also useful for people who want to lose weight.
I recently found out I have diabetes and that prompted me to start work on this project. It's open source, so you can use the code for your own version and publish it under the license terms if you want to. I'm sure this program can be modified for use with something else besides the Glycemic Index. I intend to add more fields to for collecting all the info about carbs (fiber, sugar, etc.). Right now it only has total carbs.
I've tried this with both Just BASIC and Liberty BASIC in Linux Wine and in a Windows XP virtual machine. Let me know if there are any issues. Future posts of this code may be linked to a page at my website; as the code will probably get too big to post here.
The item in the "Search" menu will search the internet for the Glycemic Index of whatever food name you put in the first field at the top right of the screen, which is not labeled, but is the "food name" field. And when you save, the program automatically calculates the Glycemic Load for you as long as you have entered the Glycemic Index and the amount of carbs in a serving. You can learn how these numbers are helpful in your diet by googling "glycemic index" and "glycemic load". It's also useful for people who want to lose weight.
'--- Glycemic Index Database Program for Diabetics v0.1
'--- and others who use the GI in their diet.
'--- Open source - Creative Commons
'--- https://creativecommons.org/licenses/by/4.0/legalcode
dim food$(5000,8), display$(5000)
index=1
browser$="C:\Program Files\Mozilla Firefox\firefox.exe"
[start]
'--- GET SIZE OF DATABASE ---
open "glycemicIndex.dta" for append as #1
numBytes = lof(#1)
close #1
'--- IF THE DATABASE HAS MORE THAN 0 BYTES, OPEN ---
'--- AND READ IN THE RECORDS (carraige return delimited)
if numBytes>0 then
numfoods=0
open "glycemicIndex.dta" for input as #1
while eof(#1)=0
numfoods=numfoods+1
[getdata]'--- LOOP TO ELIMINATE BLANK RECORDS
line input #1, food$(numfoods,1)
if food$(numfoods,1)="" then goto [getdata]
display$(numfoods)=food$(numfoods,1)'--- ARRAY FOR THE LISTBOX ---
line input #1, food$(numfoods,2)
line input #1, food$(numfoods,3)
line input #1, food$(numfoods,4)
line input #1, food$(numfoods,5)
line input #1, food$(numfoods,6)
line input #1, food$(numfoods,7)
line input #1, food$(numfoods,8)
wend
close#1
'--- SORT THE RECORDS ALPHABETICALLY
sort food$(),1,numfoods,1
end if
nomainwin
WindowWidth=DisplayWidth
ListWidth=int(WindowWidth/2)-10
WindowHeight=DisplayHeight-40
UpperLeftX=1
UpperLeftY=1
'--- MENU
menu #main, "&File", "&New", [new],_
"&Open", [open], "&Save", [save],|,_
"E&xit", [quit]
menu #main, "&Search", "&Glycemic Index", [search]
menu #main, "&Help", "&License Summary", [license]
'--- CONTROLS
listbox #main.foods, display$(), [open], 5,5,ListWidth,500
textbox #main.food, ListWidth+10,30,ListWidth,30
statictext #main.st, "Glycemic Index (GI) ___",ListWidth+10,70,210,25
textbox #main.GI, ListWidth+225,65,80,30
statictext #main.st, "Glycemic Load (GL) ___ ",ListWidth+10,107,210,25
textbox #main.GL, ListWidth+225,100,80,30
statictext #main.st, "GL of whole container _ ",ListWidth+10,140,210,25
textbox #main.GLcontainer, ListWidth+225,135,80,30
statictext #main.st, "Servings Per Container _",ListWidth+10,175,215,25
textbox #main.servings, ListWidth+225,170,80,30
statictext #main.st, "Serving Size grams/ml _",ListWidth+10,210,210,25
textbox #main.servingsize, ListWidth+225,205,80,30
statictext #main.st, "Calories ____________",ListWidth+10,245,210,25
textbox #main.calories, ListWidth+225,240,80,30
statictext #main.st, "Carbohydrates _______ ",ListWidth+10,280,210,25
textbox #main.carbs, ListWidth+225,275,80,30
'--- OPEN WINDOW
open "GLYCEMIC INDEX DATA" for window as #main
print #main, "trapclose [quit]"
print #main, "font 14"
print #main.food, display$(index)
print #main.foods, "selectindex ";str$(index)
print #main.foods, "setfocus"
print #main.food, "!font 14 bold"
print #main.food, food$(index,1)
print #main.GI, food$(index,2)
print #main.GL, food$(index,3)
print #main.GLcontainer, food$(index,4)
print #main.servings, food$(index,5)
print #main.servingsize, food$(index,6)
print #main.calories, food$(index,7)
print #main.carbs, food$(index,8)
wait
[license]
runDLL$="rundll32.exe url.dll,FileProtocolHandler"
runner$=runDLL$+" https://creativecommons.org/licenses/by/4.0/"
run runner$
wait
[search]
print #main.food, "!contents? foodName$"
length=len(foodName$)
foodTitle$=""
for i=1 to length
char$=mid$(foodName$,i,1)
if char$=" " then char$="+"
foodTitle$=foodTitle$+char$
next i
runDLL$="rundll32.exe url.dll,FileProtocolHandler"
runner$=runDLL$+" https://duckduckgo.com/?q=glycemic+index+of+"+foodTitle$
run runner$
wait
[open]' EVENTUALLY THIS WILL JUST PRINT THE DATA TO THE VARIOUS FIELDS INSTEAD OF
' LOOPING BACK TO THE BEGINNING OF THE PROGRAM. BUT IT WORKS FINE LIKE THIS.
print #main.foods, "selectionindex? index"
close #main
goto [start]
[new]
index=numfoods+1
numfoods=numfoods+1
print #main.food, ""
print #main.GI, ""
print #main.GL, ""
print #main.GLcontainer, ""
print #main.servings, ""
print #main.servingsize, ""
print #main.calories, ""
print #main.carbs, ""
print #main.food, "!setfocus"
wait
[save]
'--- GET THE DATA FROM THE FORM
print #main.food, "!contents? foodName$"
print #main.GI, "!contents? glycemicIndex$"
print #main.GL, "!contents? glycemicLoad$"
print #main.GLcontainer, "!contents? GLcontainer$"
print #main.servings, "!contents? servings$"
print #main.servingsize, "!contents? servingSize$"
print #main.calories, "!contents? calories$"
print #main.carbs, "!contents? carbs$"
'--- CALCULATE THE GLYCEMIC LOAD FROM GI AND CARBS
if glycemicIndex$<>"" and carbs$<>"" then
GI=val(glycemicIndex$)
carbs=val(carbs$)
GL=(GI*carbs)/100
glycemicLoad$=using("###", GL)
servings=val(servings$)
GLcontainer=GL*servings
GLcontainer$=using("###", GLcontainer)
end if
'--- PUT DATA INTO THE DIMENSIONED ARRAY
food$(index,1)=foodName$
food$(index,2)=glycemicIndex$
food$(index,3)=glycemicLoad$
food$(index,4)=GLcontainer$
food$(index,5)=servings$
food$(index,6)=servingSize$
food$(index,7)=calories$
food$(index,8)=carbs$
'--- FOR SOME REASON THE FIRST RECORD IS SOMETIMES BLANK
'--- WHICH IS WHY I HAVE THIS IF THEN BEFORE UPDATING
'--- THE FILE.
if food$(index,1)<>"" then
open "glycemicIndex.dta" for output as #1
for i=1 to numfoods
print #1, food$(i,1)
print #1, food$(i,2)
print #1, food$(i,3)
print #1, food$(i,4)
print #1, food$(i,5)
print #1, food$(i,6)
print #1, food$(i,7)
print #1, food$(i,8)
next i
close#1
end if
close #main
goto [start]
wait
[quit]
close #main
end