Skip to content

Instantly share code, notes, and snippets.

@LucienBrule
Created February 23, 2017 20:39
Show Gist options
  • Save LucienBrule/b2e9d0a4503d3b5990dae1b681447de8 to your computer and use it in GitHub Desktop.
Save LucienBrule/b2e9d0a4503d3b5990dae1b681447de8 to your computer and use it in GitHub Desktop.
'@author: Lucien Brule
'@description: Implements some functionality from the RPI CSCI 1010 harbor lights lab.
Option Strict On
Option Explicit On
Public Class frmSweetVbDemo
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
'Set all of the textboxes.Text to ""
tbAmountDue.Text = ""
tbUnitsOrdered.Text = ""
End Sub
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
'1. Declare local variables that we need (price per unit, number of orders)
Dim intPricePerUnit As Integer
Dim intAmount As Integer
Dim intResult As Integer
'2. Assign initial values to the varaiables you just declared (zero in both cases)
intPricePerUnit = 0
intAmount = 0
'3. Parse user input and assign to our variables
If Not Integer.TryParse(tbUnitsOrdered.Text, intAmount) Then
MessageBox.Show("Not a number")
Exit Sub
End If
'4. Break down logic and do the appropriate thing
If intAmount < 10 Then
intPricePerUnit = 5
ElseIf intAmount < 30 Then
intPricePerUnit = 4
ElseIf intAmount > 30 Then
intPricePerUnit = 3
End If
'Calculate what the price should be.
intResult = intAmount * intPricePerUnit
'5. Tell the user what you just did.
tbAmountDue.Text = FormatCurrency(intResult)
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment