post
poster: Comrade-Sergei
description: Little Fat/Calorie calculator
language: Visual Basic
[download]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Public Class MainForm

    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click
        Me.Close()
    End Sub

    Private Sub calcButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calcButton.Click
        Dim calories As Integer
        Dim fatGrams As Integer
        Dim fatCalories As Integer
        Dim fatPercent As Decimal
        Dim message As String
        Dim isConverted1 As Boolean
        Dim isConverted2 As Boolean

        isConverted1 = Integer.TryParse(caloriesTextBox.Text, calories)
        isConverted2 = Integer.TryParse(fatGramsTextBox.Text, fatGrams)

        If isConverted1 = False Then
            MessageBox.Show("The value for calories must be numeric")
        End If
        If isConverted2 = False Then
            MessageBox.Show("The value for fat grams must be numeric")
        End If



        If isConverted1 AndAlso isConverted2 Then
            fatCalories = fatGrams * 9
            fatPercent = Convert.ToDecimal(fatCalories) / Convert.ToDecimal(calories)
            fatCalsLabel.Text = fatCalories.ToString
            fatPercentLabel.Text = fatPercent.ToString("P2")
            If fatPercent > 0.3D Then
                MessageBox.Show("This food is high in fat")
            Else : MessageBox.Show("This food is not high in fat")
            End If
        End If
        caloriesTextBox.Focus()
    End Sub
End Class