Guest User

Untitled

a guest
Oct 21st, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit On
  2. Option Strict On
  3. Option Infer Off
  4.  
  5. Public Class MainForm
  6.  
  7.     Private Sub btnCalc_Click(ByVal sender As Object, _
  8.                                   ByVal e As System.EventArgs) _
  9.                                   Handles btnCalc.Click
  10.  
  11.  
  12.  
  13.         ' Declare variables
  14.  
  15.         Dim strCurrentMonth As String
  16.  
  17.         Dim decCurrentSales As Decimal = 0D
  18.         Dim decCurrentExpenses As Decimal = 0D
  19.         Dim decCurrentProfit As Decimal = 0D
  20.  
  21.         Dim decAvgSales As Decimal = 0D
  22.         Dim decAvgExpenses As Decimal = 0D
  23.         Dim decAvgProfit As Decimal = 0D
  24.  
  25.         Dim decTotalSales As Decimal = 0D
  26.         Dim decTotalExpenses As Decimal = 0D
  27.         Dim decTotalProfit As Decimal = 0D
  28.  
  29.         Dim decMargin As Decimal
  30.  
  31.         Dim cntMonths As Integer = 0
  32.  
  33.         ' Clear current month label contents
  34.        lblCurrentMonth.Text = String.Empty
  35.         lblCurrentSales.Text = String.Empty
  36.         lblCurrentExpenses.Text = String.Empty
  37.         lblCurrentProfit.Text = String.Empty
  38.  
  39.  
  40.         ' Loop!
  41.        Do
  42.             ' Assign
  43.            strCurrentMonth = InputBox("Enter the month: ", "First Month")
  44.  
  45.             ' If the user entered a month (or anything). This way is filthy.
  46.            If strCurrentMonth > "" Then
  47.  
  48.                 ' Count months added
  49.                cntMonths = cntMonths + 1
  50.  
  51.                 ' Parse strings to decimals
  52.                Decimal.TryParse(InputBox("Enter the sales amount for " & strCurrentMonth, "Sales"), decCurrentSales)
  53.                 Decimal.TryParse(InputBox("Enter the expense amount for " & strCurrentMonth, "Expenses"), decCurrentExpenses)
  54.  
  55.                 ' math stuff
  56.                decCurrentProfit = decCurrentSales - decCurrentExpenses
  57.  
  58.                 decTotalSales = decTotalSales + decCurrentSales
  59.                 decTotalExpenses = decTotalExpenses + decCurrentExpenses
  60.                 decTotalProfit = decTotalSales - decTotalExpenses
  61.  
  62.                 decAvgSales = decTotalSales / cntMonths
  63.                 decAvgExpenses = decTotalExpenses / cntMonths
  64.                 decAvgProfit = decTotalProfit / cntMonths
  65.             Else
  66.                 ' No input, so exit loop
  67.                Exit Do
  68.             End If
  69.  
  70.             ' Profit margin math:
  71.            decMargin = decTotalProfit / decTotalSales
  72.  
  73.  
  74.             If decMargin >= 0.1 Then
  75.                 lblMsg.Text = "The profit margin of " & Format(Convert.ToString(decMargin), "Percent") & " is great performance."
  76.             ElseIf decMargin >= 0.05 Then
  77.                 lblMsg.Text = "The profit margin of " & Format(Convert.ToString(decMargin), "Percent") & " is average performance."
  78.             Else
  79.                 lblMsg.Text = "The profit margin of " & Format(Convert.ToString(decMargin), "Percent") & " is subpar performance."
  80.             End If
  81.  
  82.             ' Show labels
  83.            lblCurrentSales.Text = Format(Convert.ToString(decCurrentSales), "Currency")
  84.             lblCurrentExpenses.Text = Format(Convert.ToString(decCurrentExpenses), "Currency")
  85.             lblCurrentProfit.Text = Format(Convert.ToString(decCurrentProfit), "Currency")
  86.  
  87.             lblAvgSales.Text = Format(Convert.ToString(decAvgSales), "Currency")
  88.             lblAvgExpenses.Text = Format(Convert.ToString(decAvgExpenses), "Currency")
  89.             lblAvgProfit.Text = Format(Convert.ToString(decAvgProfit), "Currency")
  90.  
  91.             lblTotalMonths.Text = Convert.ToString(cntMonths)
  92.             lblTotalSales.Text = Format(Convert.ToString(decTotalSales), "Currency")
  93.             lblTotalExpenses.Text = Format(Convert.ToString(decTotalExpenses), "Currency")
  94.             lblTotalProfit.Text = Format(Convert.ToString(decTotalProfit), "Currency")
  95.  
  96.             lblCurrentMonth.Text = strCurrentMonth
  97.  
  98.  
  99.  
  100.             'Loop while there's 'month' input
  101.        Loop While strCurrentMonth > ""
  102.  
  103.  
  104.  
  105.     End Sub
  106.  
  107.     Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
  108.  
  109.         ' Declare button result var
  110.        Dim dlgButton As DialogResult
  111.  
  112.         Dim strPROMPT As String = "Do you wish to exit?"
  113.  
  114.         ' Ask the user to confirm exit
  115.        dlgButton = MessageBox.Show(strPROMPT, "Exit?", _
  116.                                     MessageBoxButtons.YesNo, _
  117.                                     MessageBoxIcon.Question)
  118.  
  119.         ' If Yes button is hit, close application
  120.        If dlgButton = Windows.Forms.DialogResult.Yes Then
  121.             Me.Close()
  122.         End If
  123.  
  124.         ' Ideally, we'd want to use an Else or ElseIf statement to deal with the "No" button option, but in this case,
  125.        ' VB does what we need it to do, for us
  126.  
  127.     End Sub
  128.  
  129.     Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
  130.  
  131.         lblTotalMonths.Text = String.Empty
  132.         lblTotalExpenses.Text = String.Empty
  133.         lblTotalSales.Text = String.Empty
  134.         lblTotalProfit.Text = String.Empty
  135.  
  136.         lblAvgProfit.Text = String.Empty
  137.         lblAvgExpenses.Text = String.Empty
  138.         lblAvgSales.Text = String.Empty
  139.  
  140.         lblCurrentExpenses.Text = String.Empty
  141.         lblCurrentMonth.Text = String.Empty
  142.         lblCurrentProfit.Text = String.Empty
  143.         lblCurrentSales.Text = String.Empty
  144.  
  145.         lblMsg.Text = String.Empty
  146.  
  147.  
  148.     End Sub
  149. End Class
Add Comment
Please, Sign In to add comment