'Script (c) Dr. Don Hall 'Last updated: 09 FEB 2001 by Lauren Smith Sub cmdCompute_onclick() 'Data Validation: Height and Weight 'Height must be >= 140 and <= 220 'Weight must be >= 10 and <= 120 If ValidateInput(txtHt.Value, 140, 220) Then If ValidateInput(txtWt.Value, 10, 120) Then 'Calculate and display the BMI BMI = (txtWt.Value) / (txtHt.Value/100) ^ 2 txtBMI.Value = FormatNumber(BMI, 1) Else MsgBox "Ati omis inscrierea greutatii in casuta corespunzatoare. Valorile acceptate sunt cuprinse intre 10 si 120.", vbOKOnly, "Data Entry Error" Exit Sub End If Else MsgBox "Ati omis inscrierea inaltimii in casuta corespunzatoare. Valorile acceptate sunt cuprinse intre 140 si 220 cm", vbOKOnly, "Data Entry Error" Exit Sub End If 'Data Validation: 'Desired BMI must be between 17 and 27 'Min must be smaller than max If ValidateInput(txtDesiredBMI1.Value, 17, 27) Then If ValidateInput(txtDesiredBMI2.Value, 17, 27) Then If txtDesiredBMI1.Value < txtDesiredBMI2.Value Then 'Calculate and Display the Weight Goals txtWtGoal1.Value = CInt((txtHt.Value / 100) ^ 2 * txtDesiredBMI1.Value) txtWtGoal2.Value = CInt((txtHt.Value / 100) ^ 2 * txtDesiredBMI2.Value) Else MsgBox "Limita superioara a IMC recomandabil trebuie sa fie mai mare decat limita inferioara.", vbOKOnly, "Data Entry Error" Exit Sub End If Else MsgBox "Limita superioara a IMC recomandabil trebuie sa fie sub 27.", vbOKOnly, "Data Entry Error" Exit Sub End If Else MsgBox "Limita inferioara a IMC recomandabil trebuie sa fie cel putin 17.", vbOKOnly, "Data Entry Error" Exit Sub End If End Sub Sub radioMen_onclick() 'txtName.value = radioMen.value If radioMen.Value = 1 Then txtDesiredBMI1.Value = 20 txtDesiredBMI2.Value = 25 End If End Sub Sub radioWomen_onclick() 'txtName.value=radioWomen.value If radioWomen.Value = 2 Then txtDesiredBMI1.Value = 20 txtDesiredBMI2.Value = 23 End If End Sub Function ValidateInput(strInputData, dMin, dMax) 'Validate user input data: 'Returns True if it is a number and is equal to or between min and max 'Otherwise it returns false. If IsNumeric(strInputData) Then If CDbl(strInputData) <= dMax And CDbl(strInputData) >= dMin Then ValidateInput = True Exit Function End If End If 'Otherwise... ValidateInput = False End Function Sub CmdClear_onclick() txtName.value="" txtHt.value="" txtWt.value="" txtBMI.value="" txtWtGoal1.Value="" txtWtGoal2.Value="" radioMen.click End Sub