Untitled
unknown
plain_text
a year ago
1.4 kB
1
Indexable
Never
Public Class Form1 Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click Dim calories As Double Dim fatGrams As Double Dim caloriesFromFat As Double Dim percentage As Double If Double.TryParse(txtCalories.Text, calories) AndAlso Double.TryParse(txtFatGrams.Text, fatGrams) AndAlso calories >= 0 AndAlso fatGrams >= 0 Then caloriesFromFat = fatGrams * 9 If caloriesFromFat <= calories Then percentage = (caloriesFromFat / calories) * 100 lblPercentage.Text = "Percentage of calories from fat: " & percentage.ToString("F2") & "%" If percentage < 30 Then MessageBox.Show("The food is low in fat.") End If Else MessageBox.Show("The number of calories from fat cannot be greater than the total calories. Check your inputs.") End If Else MessageBox.Show("Please enter valid numbers for calories and fat grams.") End If End Sub Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click txtCalories.Clear() txtFatGrams.Clear() lblPercentage.Text = "" End Sub Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click Me.Close() End Sub End Class