Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit On
- Option Strict On
- Option Infer Off
- Public Class MainForm
- Private Sub btnCalc_Click(ByVal sender As Object, _
- ByVal e As System.EventArgs) _
- Handles btnCalc.Click
- ' Declare variables
- Dim strCurrentMonth As String
- Dim decCurrentSales As Decimal = 0D
- Dim decCurrentExpenses As Decimal = 0D
- Dim decCurrentProfit As Decimal = 0D
- Dim decAvgSales As Decimal = 0D
- Dim decAvgExpenses As Decimal = 0D
- Dim decAvgProfit As Decimal = 0D
- Dim decTotalSales As Decimal = 0D
- Dim decTotalExpenses As Decimal = 0D
- Dim decTotalProfit As Decimal = 0D
- Dim decMargin As Decimal
- Dim cntMonths As Integer = 0
- ' Clear current month label contents
- lblCurrentMonth.Text = String.Empty
- lblCurrentSales.Text = String.Empty
- lblCurrentExpenses.Text = String.Empty
- lblCurrentProfit.Text = String.Empty
- ' Loop!
- Do
- ' Assign
- strCurrentMonth = InputBox("Enter the month: ", "First Month")
- ' If the user entered a month (or anything). This way is filthy.
- If strCurrentMonth > "" Then
- ' Count months added
- cntMonths = cntMonths + 1
- ' Parse strings to decimals
- Decimal.TryParse(InputBox("Enter the sales amount for " & strCurrentMonth, "Sales"), decCurrentSales)
- Decimal.TryParse(InputBox("Enter the expense amount for " & strCurrentMonth, "Expenses"), decCurrentExpenses)
- ' math stuff
- decCurrentProfit = decCurrentSales - decCurrentExpenses
- decTotalSales = decTotalSales + decCurrentSales
- decTotalExpenses = decTotalExpenses + decCurrentExpenses
- decTotalProfit = decTotalSales - decTotalExpenses
- decAvgSales = decTotalSales / cntMonths
- decAvgExpenses = decTotalExpenses / cntMonths
- decAvgProfit = decTotalProfit / cntMonths
- Else
- ' No input, so exit loop
- Exit Do
- End If
- ' Profit margin math:
- decMargin = decTotalProfit / decTotalSales
- If decMargin >= 0.1 Then
- lblMsg.Text = "The profit margin of " & Format(Convert.ToString(decMargin), "Percent") & " is great performance."
- ElseIf decMargin >= 0.05 Then
- lblMsg.Text = "The profit margin of " & Format(Convert.ToString(decMargin), "Percent") & " is average performance."
- Else
- lblMsg.Text = "The profit margin of " & Format(Convert.ToString(decMargin), "Percent") & " is subpar performance."
- End If
- ' Show labels
- lblCurrentSales.Text = Format(Convert.ToString(decCurrentSales), "Currency")
- lblCurrentExpenses.Text = Format(Convert.ToString(decCurrentExpenses), "Currency")
- lblCurrentProfit.Text = Format(Convert.ToString(decCurrentProfit), "Currency")
- lblAvgSales.Text = Format(Convert.ToString(decAvgSales), "Currency")
- lblAvgExpenses.Text = Format(Convert.ToString(decAvgExpenses), "Currency")
- lblAvgProfit.Text = Format(Convert.ToString(decAvgProfit), "Currency")
- lblTotalMonths.Text = Convert.ToString(cntMonths)
- lblTotalSales.Text = Format(Convert.ToString(decTotalSales), "Currency")
- lblTotalExpenses.Text = Format(Convert.ToString(decTotalExpenses), "Currency")
- lblTotalProfit.Text = Format(Convert.ToString(decTotalProfit), "Currency")
- lblCurrentMonth.Text = strCurrentMonth
- 'Loop while there's 'month' input
- Loop While strCurrentMonth > ""
- End Sub
- Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
- ' Declare button result var
- Dim dlgButton As DialogResult
- Dim strPROMPT As String = "Do you wish to exit?"
- ' Ask the user to confirm exit
- dlgButton = MessageBox.Show(strPROMPT, "Exit?", _
- MessageBoxButtons.YesNo, _
- MessageBoxIcon.Question)
- ' If Yes button is hit, close application
- If dlgButton = Windows.Forms.DialogResult.Yes Then
- Me.Close()
- End If
- ' Ideally, we'd want to use an Else or ElseIf statement to deal with the "No" button option, but in this case,
- ' VB does what we need it to do, for us
- End Sub
- Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
- lblTotalMonths.Text = String.Empty
- lblTotalExpenses.Text = String.Empty
- lblTotalSales.Text = String.Empty
- lblTotalProfit.Text = String.Empty
- lblAvgProfit.Text = String.Empty
- lblAvgExpenses.Text = String.Empty
- lblAvgSales.Text = String.Empty
- lblCurrentExpenses.Text = String.Empty
- lblCurrentMonth.Text = String.Empty
- lblCurrentProfit.Text = String.Empty
- lblCurrentSales.Text = String.Empty
- lblMsg.Text = String.Empty
- End Sub
- End Class
Add Comment
Please, Sign In to add comment