Introduction: Nutrient Calculator

Nutritional calculator: If you enter in what you ate during a day, it will calculate how many calories, carbohydrates, fiber, fats and cholesterol you ate. This could be useful for any type of diet.

WARNING: This Instructable comes with no guarantees. There are too many factors that are not under my control. It is also not endorsing any specific diet.

This LAZY OLD GEEK went to his MD. She basically said I was pre-diabetic and sent me to a nutritionist. My nutritionist said I should watch my carbohydrates. (She said a lot of other things but I’m OLD so focused on carbs). I should limit myself to 180 grams of carbs per day. Being a GEEK, I decided to write my own nutritional logger.

The USDA has a great nutritional database with lots of information on nutrition:
http://fnic.nal.usda.gov/nal_display/index.php?info_center=4&tax_level=1
http://www.ars.usda.gov/Services/docs.htm?docid=8964

And they have a nice little program so that you can look up most anything you want and get the nutritional information on it.
http://www.nal.usda.gov/fnic/foodcomp/search/

This may have all of the information you may need. My problem is that I wanted to know all of the nutrient information for a day. The USDA databases come in different types (and versions). Since I planned to write my program in Visual Basic Express (see GPS for Lazy Old Geeks for more information on VB Express), I chose to use the Microsoft Access version. Now, don’t panic, you shouldn’t need MS Access or know how to use it to use my program.
 

Step 1: Designing Program

Unless you’re interested in writing your own program or are a glutton for details(punishment), skip this step. It is rather boring.

PROBLEM: The original database is 107mBytes and hard to work with.
SOLUTION: For anybody familiar with relational databases, you probably know they’re very complex with relationship diagrams and rules and restrictions for entering and modifying data. Well, this SR23.mdb nutritional database is one of them. For my purposes, I removed all of the relationships and tables except for the main one called ABBREV. This is the one included in this Instructable.

In relational database terminology a record is all of the information for an item. In this case a record will be a description of the item and all of the nutrients associated with that item.
For those of you who have access to MS Access, there are over 7000 records in this table. For my use, I went in and removed 1000s of these records for foods that I would probably never eat, like Alcoholic Beverages and Baby Food. I also removed several categories for vitamins and such that I don’t care about. Since everyone's tastes and eating habits are different, I left all the records in the attached database.

The core of the program is just accepting the nutrients for the selected food item, placing them in the four meal categories, then summing them up for a total. 

PROBLEM: I decided to export my daily report in CSV format, comma separated values. This makes it easier to be read into MS Excel or OpenOffice or GoogleDocs. Unfortunately, the Short Description field in the database allows commas. This would make the information unusable when read into Excel.
“CHEESE,COTTAGE,NONFAT,UNCRMD,DRY,LRG OR SML CURD”
SOLUTION: There are alternatives to comma separated like semi-colon, but I chose to replace the commas in the description field with colons.
“CHEESE:COTTAGE:NONFAT:UNCRMD:DRY:LRG OR SML CURD”
 

Step 2: Installing/using the Program

Here is the install program zipped up.

PROBLEM: Now this install version does work. Unfortunately, it doesn’t apparently have the database as MS Access, so you can’t easily modify the original data.
SOLUTION: My program does allow editing, such as changing and deleting records and that seems to work. That should be enough for most people.
An alternative is to load the complete program (source code) after you have installed Visual Basic Express. Explained in a later step.

Requirements:
1. Microsoft VISA or XP operating system
2. An Internet connection (The program will need to download any .NET files required for operation)

Copy the publish zip file to your computer.
Extract the zipped files
Run setup.exe
The install program needs an internet connection to download .Net files.

When I installed the program, for some unknown reason, it was placed in a directory called Hewlitt-Packard.
The program is called Nutrients and has a cheeseburger icon. 
The program can be uninstalled using Control Panel, Add/Remove Programs (or Uninstall a Program), Uninstall Nutrients


Using Program

Click on Nutrients or the Cheeseburger icon

Overview of program window
At the top is a menu with FILE in it. Explained later.
The next row is a toolbar for navigating and modifying the database. Also explained later.
Then there is a text box with the date in it.

Next on the left is a listing of food items in the nutritional database. They are alphabetized and you can scroll down with the mouse. If you click on one, it will appear at the top of the box and will fill in the nutrients boxes.

The middle text box shows the suggested amount of food that might be consumed. Below that is where you can change that amount to what you actually consumed.

Not so important: To the right is GmWt which is the number of grams in the Gm Wt Description. E.g., 1cup of kernels will weigh about 138 grams. The other boxes are for calories, carbs, etc. A technical explanation: These values are based on a 100 gram portion by weight. They are the gram weight for each nutrient except Cholesterol which is in mG. These are not the nutrients for the Gm Wt Description, in this case,1 cup. So in this screen, they are pretty irrelevant unless you are a nutrition Geek.

The colored text boxes are where the stuff you eat will be displayed.
 

Step 3: Entering a Percentage

Some comments about the database.
There are a lot of brand names especially for Fast food and major restaurant franchises. There are also a lot of major food manufacturers, like Campbells, Kellogs, Kraft.
Alcoholic Bev, BabyFood, Infant Formula, Snacks are separate categories. Some have major brand names under them.
The database is good but not consistent. There is a fast food category but it can be FAST FOOD, FAST FD, FST FOODS.
Lamb is categorized by country of origin. Aus-Austria? NZ-New Zealand.

So let’s say you found the food you ate, a McDonalds Double Cheeseburger but you only ate ½ of it and will save the other half for my dog, like my mother does.
Well, the Gm Wt says 1 item so in the fraction you enter .5 for ½ and select Change Weight. Now the nutrient boxes reflect the actual values you ate, e.g. 25.66 grams of carbs.
TIP: If you don’t know decimal fractions: ¼ = .25, 1/3 = .33, ½ = .5, 2/3 = .67, ¾ = .75. By the way, it doesn't have to be less than 1. If you ate two Double Cheeseburgers, put in 2.
TIP: If you click on Change Weightand it gives you an error message, either you forgot to enter the fraction or the nutrient textboxes had a blank. If one of the text boxes on the right is blank, enter a zero.

PROBLEM: If you make a mistake and want to change your percent, unfortunately, you can’t get back to the original values. 
SOLUTION: Don’t make mistakes. Unfortunately, the only thing you can do is restart the program.

Notice also that after pressing Change Weight  four little buttons appear in the middle. Aren’t I clever? With these you can now add the item to the appropriate category, say lunch and it shows up in the Lunch box. See next picture.
 

Step 4: Creating a Report

So you have your day’s food intake entered. To create a report, make sure the date in the upper left corner is the day you are entering food items for. Change it if necessary. Then click on File, Save.
Go to a directory that you want to save it to and enter a filename, such as Nov16. The .CSV extension will automatically be appended.

You can open this file with a text editor, say Notepad but it isn’t very readable.

If you have Excel, you can just click on it. With a little bit of formatting, I created an example daily nutrition log.

If you don’t have Excel, you can sign up for Google Docs (free). Open a spreadsheet and import the .CSV file. It worked for me.
I assume it will also work with Open Office.
 

Step 5: Editing the Food Database

This is not advised for the casual user, but you do have some ability to edit the food database.
(The astute observer may notice that this is a slightly different screen shot from some of the early pictures. This is the latest version.)

Just below the File icon is another toolbar. This is a database navigator.

The first part with the arrows and numbers can be used to navigate through the database. The first number is the number of the record, the second is the total number of records in the database.

Deleting records: Anyone using this program will find it cumbersome to go through 7000 food items and that many of the selections will never be used. There is a pretty easy way to delete records.

WARNING: Records cannot be added back with this program. You would have to reinstall the original program.

If the Save(floppy disk) icon is not visible, you will need to restart the program.
TIP: Clicking on Change Weight will disable Save in the navigation toolbar.
Select an item you want to delete then click on the red X in the toolbar. The deletion isn’t completed until you click on the Save icon right next to the delete, but you can delete as many records as you want with the X and then Save the changes.

Changing records: A certain amount of changes to records can be done. I couldn’t change the description. However some of the records are incomplete.
Do not attempt to change values unless you understand the following information and have the correct values.
The nutrients are based on a 100 gram sample. For example in the screen shot below, the raw abalone has 105 calories, 6.01gms of Carbohydrates, 0.107 grams of Fat mono and 85mgrams of cholesterol in a 100 gram sample.
The GmWt textbox is the # of grams in the GmWt Description. In this example 3oz of abalone weighs 85 grams. So if you change the GmWt Description, you must correct the GmWt to match.

Now if you know that one of the nutrients is incorrect and you know what the correct value is for a 100 gram sample, do this.

Restart the program if there is no Save icon in the toolbar. Go to the correct food item. Enter in the corrected nutrient. Click on the Save icon.

No other editing is possible unless you do the following(next Step):


Step 6: Installing VB Express and Nutrients

The following requires knowledge/experience with VB Express or Visual Studio.
The Nutrients.zip file contains all of the source code. Install Microsoft Visual Basic Express 2010 first.
http://www.microsoft.com/express/Downloads/

Then unzip the files and copy them into the Project directory. Mine looks something like this:
\\MICHAEL-PC\Users\Michael\Documents\Visual Studio 2010\Projects\Nutrients

Start VB express, go to File, Open Projects
Select Nutrients, select Nutrients.sln, the project will load. Now you are on your own.

Some tips about the database: The master, sr23.mdb is in the Nutrients\Nutrients directory. If you have Access or probably OpenOffice, you can edit the database. The Table ABBREV contains all of the information used by the program.

Now VB Express does some tricky things with this database. When you run in Debugger mode, it copies sr23.mdb from Nutrients\Nutrients to Nutrients\Nutrients\bin\debug directory. When you build the project and run it, it copies sr23.mdb to Nutrients\Nutrients\bin\release.
Now if you make changes to the database while running the program as described in the last step, these changes will go into the appropriate bin directory copy but not into the master copy. So if you make changes to the database with the program and want to make them permanent you need to copy sr23.mdb from the bin directory back to Nutrients\Nutrients directory.

Are you thoroughly confused? Well, I don’t blame you. VB Express is a powerful program that can do a lot of things, often very simply. I am not nearly an expert on how and why they do things so I cannot explain things any better and only tell you what I know.
 
But with VB Express, you can make changes, like add or subtract nutrient categories and use it with updated databases. I am fairly certain that sr23 is the latest released version but if there is a later release, you could replace sr23.mdb with the new one.

Step 7: Conclusions

Problem: Being a Lazy Old Geek, one of the problems I have is trying to remember all the food I ate in a day.
Solution: I sometimes use a little whiteboard to write foods down.
Problem: Being a Lazy Old Geek, I don’t know how often I will use it.

But I plan to save some of my day’s nutrients to show my nutritionist. I know my carbohydrates are a lot lower than they used to be and I actually seem to feel better, but it is quite likely that some other things like fats are out of control. Again a low carb diet was recommended only for my specific situation. By the way, the pictured cheeseburger without the bun is low carb.

I hope this program is useful to others. The information could be shown to your MD or nutritionist/dietician. It can also help you evaluate your diet and see how close you are to where you want to be.
 

Comments

author
Lulu_Flores made it!(author)2011-05-03

Hi, your instructable its really cool, I'm a nutritionist and my husband it's a software developer, a few days ago he made me a little program like yours, its so funny to find something like this made by the pacient itself. Here in mexico we use a system wich is very useful that involves portions and types of food and the nutritionist its who make the calculation about the specific nutrients and gives the patient a lot of sugesstions about how many portions of every type of food he/she can eat and with these options he/she can choose or cook his own dishes every day.

Good luck with your carbs!!

author
msuzuki777 made it!(author)2011-05-03

Thanks.
Actually, I have a nutritionist who works with my MD. She was the one that suggested I lower my carbs to about 180 grams a day. This was because my A1C(blood sugar) was a little high. She also uses portion control. After two months following her suggestions, I actually lost 19 pounds, mostly belly fat, even though I wasn't trying to lose weight. But the important thing is that I feel a lot better, have more energy and can exercise more. She also said it would help my high blood pressure and it did.
So I have gained a lot of respect for nutritionists such as yourself. My nutritionist made a major difference in my overall health.
As to writing this program, well, I was a hardware/software developer before I retired and like to stay involved. I also wrote an Instructable on a pedometer I built to monitor my daily walks. Exercise was also brought up by my nutritionist.

In this case, I would say my nutritionist was more helpful than my MD. But on the other hand, my MD was the one who referred me to a nutritionist.

About This Instructable

1,920views

5favorites

License:

Bio: Lazy Old Geek
More by msuzuki777:Senior MomentsWeather Station 5IP Time Clock Part 2
Add instructable to: