# DMB Calculator Program Build



## FinnickHog (Dec 1, 2014)

This thread is for the DMB calculator I'm working on. It will contain build notes, how it works, and each finished rendition of the executable file. I managed to dig up my old copy of Visual Basic, so I'll actually be making an executable program that will (hopefully!) do all of the math. It will basically look like a huge version of the standard Microsoft calculator, with more specific labels.

Assuming I still know what I'm doing, the calculator will ultimately be able to take your data for whatever food you want from the numbers available on this website: https://ndb.nal.usda.gov/ndb/foods?...d=&manu=&lfacet=&qlookup=&offset=0&order=desc and turn it into the dry matter basis, so that all foods you want to put in a mix are being considered equally. For example, comparing celery to freeze dried quail, the celery will be almost 100% water, while the quail will be almost 0% water. The calculator will balance out the water content of anything entered, which will then give you comparable stats for protein, fat, fiber, and sugar.

If that goes well, the next step is to make the calculator take everything you've entered for meats, veggies, and fruits, and tell you the ratio you want to use. This will take into account a total from the results you entered in step 1. I'm not sure if I'll have a separate calculator for this or if I'll add it as a side feature, but either way you'll likely have to do basic math to get your total fat/protein/fiber/sugar contents for each section. If I'm really clever I can make the program do it, but it means if you decide not to use a food you have to start over.

And if that somehow works out, I'll add a feature that tells you how much calcium supplement still needs to be added to the final mix to balance out the calciumhosphorous ratio.

I'm also going to include a spreadsheet of commonly used items and their DMB values so you don't have to keep entering chicken and broccoli over and over.

It sounds complicated now, but trust me, if it works it will make raw diets so much easier to calculate!

Here is the raw data file Kelsey and I have compiled our information into so far. Feel free to have a look, but please don't edit it without switching into suggestion mode, because I'm using it to build the calculator: https://docs.google.com/document/d/1woVqRVbpp_9DOhqmr_bGYxTz1k6MXP2YxzEEcIwjyT0/edit?usp=sharing

I should have a prototype for everyone to play with by the end of next week. I'll keep updating here as it grows and becomes functional.


----------



## twobytwopets (Feb 2, 2014)

This will be so great for us non-math people. The scariest thing about any diet is the thought that "I have to math, I don't math" 
I joked in college that my math classes should have started out with crayons and flashcards with just numbers!


----------



## FinnickHog (Dec 1, 2014)

I was never any good with math, really. But for some reason when I'm entering it as an equation into a program it works fine. Unfortunately I just had to test my equation to make sure it was working, and that took 45 minutes :lol:. I've got it, though, I think!

The first rendition will only work if a total weight of 100 grams is set, but the accompanying website has that in the first column all ready to go. So it's not a huge deal yet, I just don't want to have to do any more algebra until I'm sure my totals out of 100g is working. That said, here's my current formula on its own, not in code yet:

total weight (grams) = g
water (g) = w

protein (g) = p
fat (g) = fa
fiber (g) = fi
sugar (g) = s
(protein, fat, fiber, sugar all work with the same equation, so they have been labeled i for input)

t-w = d (DMB% of dry matter). t minus w equals d.
ix100/d = result. i multiplied by 100 divided by d equals result.

So if we test it, and please do, because I might be completely wrong, this happens:

https://ndb.nal.usda.gov/ndb/foods/show/112?manu=&fgcd=
Egg, Whole, Raw, Fresh

t = 100g
w = 76.15
p = 12.56
fa = 9.51
fi = 0
s = 0.37

t-w = d gives me 100-76.15 = 23.85
ix100/d = result gives me (for protein (p)) 12.56x100/23.85 = 52.66% DMB for protein.

I've tested it a few times and it seems to be working. I've just asked a very mathy friend to play with it a bit and he should be able to give us a conclusive answer as to whether or not it works pretty quickly. And then it's coding time! I'm working on the layout in the meantime and it should look pretty good.


----------



## FinnickHog (Dec 1, 2014)

I just got the all clear on the formula, so on to phase 2.

It doesn't do anything yet, but it sure is pretty!










Taking a dinner break and then going through some tutorials to remind myself how to actually code the button at the bottom to do something. This is the part that will take time :lol:.


----------



## FinnickHog (Dec 1, 2014)

Well it came back to me a _lot_ faster than I thought it would. Right now the program can only handle total weights of 100 grams, so be sure to use the first column in the nutritional information website.

The website again is: https://ndb.nal.usda.gov/ndb/foods?...d=&manu=&lfacet=&qlookup=&offset=0&order=desc

The formula should be accurate and the numbers in the grey boxes on the right will be your DMB% of each protein, fat, fiber, and sugar. Feel free to leave sugar or fiber blank if you're not worried about them right now. It will only crash if you blank out the 0s completely :lol:.

If anyone wants to try inputting numbers from the website or off the top of your heads and then doing the math longhand using the equation above it would really be appreciated. Once my math guy gets home I'll have him mess with it as well.

But basically, this version works!

To use it, input your desired food's total weight (100 grams!), the water weight, and then the protein, fat, fiber, and sugar weights. It will output into a percentage. Write this percentage down in columns of protein, fat, fiber, and sugar, and move on to the next food. Once you have a full list, add your total protein percentages together and divide by the number of foods on the list to get the total percentage of protein in your mix. Do the same for fat, fiber, and sugar, as needed, and then compare this to the data in the nutrition stickies. I'm hoping to make a calculator for this as well, but it's not in there yet.

Bugs/fixes:
- If protein, fat, fiber, or sugar are blanked out the program will crash.
- If protein, fat, fiber, or sugar are inputted as higher than the total dry matter percentage, they will still attempt to display and will give you over 100%
-Only accepts 100g total weight right now, because math is hard and I am lazy

-Will be rounding outputs to 00.00 digits and adding a % sign.
-Will eventually allow for total weights other than 100g, in case someone wants the DMB of a single egg, for example.
-Needs more work with debugging and error messages.

It's zipped, so you'll have to extract it and then run the .exe. I made it myself, but if you're nervous, virus scan it as soon as you extract it.

Please post here with any questions or concerns!


----------



## FinnickHog (Dec 1, 2014)

Just wanted to bump this in case anyone didn't see the original update. The file attached to the post above is a working DMB calculator.

I'm in the process of figuring out how to get it to output the total diet's DMB so you can tell if the meal you've developed is within the appropriate ranges or not without having to do it manually. I'll hopefully have that done soon.


----------



## FinnickHog (Dec 1, 2014)

Ooookay. So the program now has 3 sections. Section 1 will take one ingredient's data from the website above (or insect spreadsheet once it's done) and convert it into DMB %. You then take those outputted numbers and put them into the corresponding boxes (insects, meat, veggies, fruit, then protein, fat, or fiber) in Section 2 and do your next ingredient until you're done.

Once Section 2 is completed, it will calculate your protein, fat, and fiber contents for each type (insects, meat, veg, fruit).

Section 3 has adjustable ratio boxes so you can decide how much of each ingredient type you want to have in your final mix, and then that section will tell you if your completed mix is within the parameters I've set.

Those parameters are:
Protein: 20%-35%
Fat: 10%-17%
Fiber: 5%-15%

These are just based on the average hedgehog and obviously won't apply to every single hedgie, so some people will have to use higher or lower fat content goals. It will still work outside these parameters so that's not a problem.

Section 2 is still throwing a few temper tantrums. Right now, *if your food has a value of 0 for protein, fat, or fiber, the Section 2 program can't read it as a number, so you need to put "0.01"*

*If you don't use all of the boxes in Section 2, fill any unused ones with 0s so that the program doesn't have a hissy fit*. I'm still debugging this, so it *will* work properly eventually.

(for coders: it doesn't recognize an empty box as an empty box and I can't remember the command to tell it to safely ignore empty boxes, so 0 is set as my null value)

Other than that, it should be working as intended! Please view the readme for more in depth info!

I'm going to make an insect DMB value spreadsheet next so there's a reliable source for that data available, but for now use the website in my first post for meat, veg, and fruit data.

Once I'm done all the spreadsheets and if I can get it working, the calcium calculator, I'll post a new thread that will hopefully be sticky-worthy.


----------



## FinnickHog (Dec 1, 2014)

It has come to my attention that not everyone has a custom built superbeast of a PC. So. The width of this massive program is about 1600 pixels wide, and if your resolution is lower than that it'll dangle off the edge or crop short.

I'm working on how to scale it by dragging the lower right corner, but in the meantime, you can drag *THIS VERSION* (not the last version) off your screen to the left or right and then resize the window by dragging it wider to see the part that's off your screen. You can also hit the maximize button and that might help, but I don't know because my resolution is so insane I can't drop it low enough to have a problem.

First world debugging problems. :roll:

I've also modified section 1 to take different weights other than 100 grams so you can do a single egg now, or one mealworm if you really want, or whatever else your weight is. Outputted numbers now format to have 2 decimal places instead of however many there are, so that repeating numbers like 3.333333333333333333etc now crop to 3.33 and 6.666666666 now crops to 6.67.

Section 2 is still huffy, so make sure you add those 0s in empty slots!


----------



## Draenog (Feb 27, 2012)

Great idea! Will check it out somewhere this week when I have time


----------



## FinnickHog (Dec 1, 2014)

Thanks much!


----------



## FinnickHog (Dec 1, 2014)

Okay, if you have an older computer, this version has a much smaller footprint and should fit more nicely on your screen.

Also, if you run the program and it says you're missing a .dll file, you'll have to download it. This walks you through that: http://superuser.com/questions/5198...sing-when-starting-visual-basic-6-application


----------



## FinnickHog (Dec 1, 2014)

Aaaand that walkthrough doesn't seem to work for Windows 8 or 10. I have 7, naturally. I'm installing Visual Studio 2015 now to see if I can plop the program's code into there and have it work on newer systems. Knowing programming, it won't transfer seamlessly and I'll have to do at least some minor tweaking.

If you get the missing dll error, you'll have to wait for the new program. Otherwise, the two versions above work great!


----------



## FinnickHog (Dec 1, 2014)

Plopping was completely unsuccessful. It was basically like learning Spanish for a year and then being told the final exam is in Italian. It looks like something I know but nothing quite fits.

So now I'm trying to find a way to have the .dll install when you run the calculator. I'm remembering why I got out of programming now :lol:.

Please let me know if either of the two versions above work for you, and if they don't, type out the error message for me.


----------

