Fellow colleagues, good day to you.
I'll go straight to the point: I'm working on a database and I need to create a function to calculate the BMI (Body Mass Index) from the weight and height of a person.
So far, I've come up with this:
Where varpeso is the weight in kg and varaltezza is the mass of said person in cm (thus the division by 100, for the BMI requires the height to be in meters, not centimeters).
This function works only if the fields that I take the values from are of a numeric type. However, I'd rather them be strings, because I'm using two input masks for these fields, so that I don't have to manually put two labels showing "kg" and "cm" in the form, respectively.
My idea was to convert them from a string type to a numeric value.
I admit that I've done some Visual Basic 6.0 programming when I was in high school, but never done anything even remotely related to databases during that time. Plus, it's been a while since I've last done any programming at all, and quite frankly I don't remember how the single characters in the strings were handled.
I still remember how that's done in Turbo Pascal, though.
It should be something like this:
The counter goes from 1 to 3 because the input mask I'm using allows to insert only 3 characters.
How can this be translated to VBA? And is it possible to handle a single character in a text type field through VBA?
Thanks in advance.
I'll go straight to the point: I'm working on a database and I need to create a function to calculate the BMI (Body Mass Index) from the weight and height of a person.
So far, I've come up with this:
Code:
Public Function bmi(varpeso, varaltezza As Double) As Double
Dim varbmi As Double
Dim varmetri As Double
varmetri = varaltezza / 100
varbmi = varpeso / (varmetri ^ 2)
bmi = varbmi
End Function
This function works only if the fields that I take the values from are of a numeric type. However, I'd rather them be strings, because I'm using two input masks for these fields, so that I don't have to manually put two labels showing "kg" and "cm" in the form, respectively.
My idea was to convert them from a string type to a numeric value.
I admit that I've done some Visual Basic 6.0 programming when I was in high school, but never done anything even remotely related to databases during that time. Plus, it's been a while since I've last done any programming at all, and quite frankly I don't remember how the single characters in the strings were handled.
I still remember how that's done in Turbo Pascal, though.
It should be something like this:
Code:
for k := 1 to 3 do number := number + (stringname[k]*10^k);
How can this be translated to VBA? And is it possible to handle a single character in a text type field through VBA?
Thanks in advance.