Treating table fields as strings (1 Viewer)

Lehti

New member
Local time
Today, 16:43
Joined
Apr 27, 2013
Messages
5
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:
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
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:
Code:
for k := 1 to 3 do number := number + (stringname[k]*10^k);
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.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 15:43
Joined
Sep 12, 2006
Messages
15,680
why strings?

let users enter numbers as numbers.

put a little label with kg, or cm (or m) after the entrybox , and sense check the value


eg height must be between 150 and 250 cms
weight between 40kg and 300kg maybe
 

Lehti

New member
Local time
Today, 16:43
Joined
Apr 27, 2013
Messages
5
I did, in fact, but the form looked awful, since the labels were outside the entry boxes.
Also, I could use handling the fields as strings through VBA in the future.
 

Users who are viewing this thread

Top Bottom