Assistance creating a Sub Procedure named "(FundingResource(Balance))" Visual Basic - vb.net

I am working on a program that consists of three event procedures (in other words, three different task buttons: “Select Media and Estimated Fund,” “Add Agencies,” and “Generate Report”).
When the “Select Media and Estimated Fund” button is clicked, input boxes should pop up and ask user to input a balance and that balance will be put through the formula of (Balance = Balance * (1 + interest rate). The balance the user inputs can not be less that $500.00 or more than $3000.00.
( Estimated Budget should be calculated depending on your selection of funding resources (Funding Resource is the type of account they choose, Savings (7% interest rate) and Corporate (5% interest Rate) The calculated results should appear in the disabled textbox right next to the “Estimated Budget” textbox. If you selected two resources, each estimated budget should be summarized together. The calculation process should be called a sub procedure defined as “FundingResource (Balance)” in the event procedure.
Please be aware of the current year, 2013. Now, the report is prepared in year 2013, but the balance should be calculated for your selected year (e.g., 2015, 2016, 2017). Think about the topic of repetition to determine the ending balance during your selected year.
I have completed the code I believe but don't know how to put it into a Sub Procedure. The code for the above question is in "btnMediaEstimatedFund".
Public Class Form1
Private Sub btnMediaEstimatedFund_Click(sender As Object, e As EventArgs) Handles btnMediaEstimatedFund.Click
Dim interestRate, balance, initialBalanceSavings, initialBalanceCorporate, finalBalance As Double
txtBoxEstimatedBudget.Enabled = False
txtBoxAgenciesNeeded.Enabled = False
If radButtonTraditional.Checked Then
txtBoxAgenciesNeeded.Text = 3
ElseIf radButtonEMedia.Checked Then
txtBoxAgenciesNeeded.Text = 2
End If
If checkBoxSavings.Checked Then
interestRate = 0.07
ElseIf checkBoxCorporate.Checked Then
interestRate = 0.05
ElseIf checkBoxCorporate.Checked And checkBoxSavings.Checked Then
interestRate = 0.12
End If
initialBalanceSavings = InputBox("Please Enter a balance for SAVINGS account between $500.00 and $3000.00")
If initialBalanceSavings > 3000 Then
InputBox("Please enter a balance for SAVINGS account equal to or below $3000.00 and no less than $500.00")
ElseIf initialBalanceSavings < 500 Then
InputBox("Please enter a balance for SAVINGS account equal to or above $500.00 and no more than $3000.00")
End If
initialBalanceCorporate = InputBox("Please Enter a balance for CORPORATE account between $500.00 and $3000.00")
If initialBalanceCorporate > 3000 Then
InputBox("Please enter a balance for CORPORATE account equal to or below $3000.000 and no less than $500.00")
ElseIf initialBalanceCorporate < 500 Then
InputBox("Please enter a balance for CORPORATE account equal to or above $500.00 and no more than $3000.00")
Else
finalBalance = initialBalanceCorporate + initialBalanceSavings
balance = finalBalance * (1 + interestRate)
txtBoxEstimatedBudget.Text = balance
End If
End Sub
Private Sub btnAddAgencies_Click(sender As Object, e As EventArgs) Handles btnAddAgencies.Click
Dim dict As Dictionary(Of String, Integer) = New Dictionary(Of String, Integer)()
dict.Add("U-Ad ($350)", 350)
dict.Add("Striker ($190)", 190)
dict.Add("New Ad ($250)", 250)
dict.Add("Samson ($530)", 530)
dict.Add("J & R ($420)", 420)
dict.Add("Victory ($120)", 120)
Dim selectedItems = (From i In lstBoxAgenciesList.SelectedItems).ToArray()
Dim total As Integer = 0
For Each selectedItem In selectedItems
lstBoxSelectedList.Items.Add(selectedItem)
lstBoxAgenciesList.Items.Remove(selectedItem)
Next
For Each item In lstBoxSelectedList.Items
total += dict(item)
Next
txtBoxEstimatedCost.Text = FormatCurrency(total.ToString())
End Sub
Private Sub btnGenerateReport_Click(sender As Object, e As EventArgs) Handles btnGenerateReport.Click
Dim employeeLevel, year, selectedMedia, numberOfAgencies As String
Dim today As Date
today = CStr(dtpToday.Text)
Name = CStr(txtBoxCreator.Text)
employeeLevel = CStr(lstBoxResults.Text)
year = CStr(lstBoxResults.Text)
selectedMedia = CStr(lstBoxResults.Text)
numberOfAgencies = CStr(txtBoxAgenciesNeeded.Text)
dtpToday.Text = FormatDateTime(today, DateFormat.ShortDate)
If radButtonManager.Checked Then
employeeLevel = "Manager"
ElseIf radButtonStaff.Checked Then
employeeLevel = "Staff"
End If
If radButton2015.Checked Then
year = "2015"
ElseIf radButton2016.Checked Then
year = "2016"
ElseIf radButton2017.Checked Then
year = "2017"
End If
If radButtonTraditional.Checked Then
selectedMedia = "Traditional Media (TV, Radio)"
ElseIf radButtonEMedia.Checked Then
selectedMedia = "New e-Media (SNS, e-Mail)"
End If
lstBoxResults.Items.Add("=======================================")
lstBoxResults.Items.Add(" ")
lstBoxResults.Items.Add("Date : " & today)
lstBoxResults.Items.Add(" ")
lstBoxResults.Items.Add("Reporting Entity : " & Name)
lstBoxResults.Items.Add(" ")
lstBoxResults.Items.Add("Level of Employee : " & employeeLevel)
lstBoxResults.Items.Add(" ")
lstBoxResults.Items.Add("=======================================")
lstBoxResults.Items.Add(" ")
lstBoxResults.Items.Add("Year" & " " & year & " " & "Budget of Advertising Report")
lstBoxResults.Items.Add(" ")
lstBoxResults.Items.Add("=======================================")
lstBoxResults.Items.Add(" ")
lstBoxResults.Items.Add("Total Estimated Cost : " & FormatCurrency(txtBoxEstimatedCost.Text))
lstBoxResults.Items.Add(" ")
lstBoxResults.Items.Add("Total Estimated Budget : " & FormatCurrency(txtBoxEstimatedBudget.Text))
lstBoxResults.Items.Add(" ")
lstBoxResults.Items.Add("Selected Media : " & selectedMedia)
lstBoxResults.Items.Add(" ")
lstBoxResults.Items.Add("Number of Agencies Involved : " & numberOfAgencies)
lstBoxResults.Items.Add(" ")
lstBoxResults.Items.Add("=======================================")
End Sub
End Class

Update
Your inputboxes are incorrect, if an invalid value is entered consistently the routine will drop through to the next lines of code!
They should appear as below.
Do
inputtedData = InputBox("Please Enter a balance for SAVINGS account between $500.00 and $3000.00", "Initial Savings Balance", "0.00")
If inputtedData = "" Then
MsgBox("User chose to Cancel calculation!")
Exit Sub
Else
initialBalanceSavings = CType(inputtedData, Single)
If initialBalanceSavings > 3000 Or initialBalanceSavings < 500 Then MsgBox("Please enter a balance for SAVINGS account equal to or above $500.00 and no more than $3000.00", MsgBoxStyle.Critical, "Error")
End If
Loop Until initialBalanceSavings >= 500 And initialBalanceSavings <= 3000
Do
inputtedData = InputBox("Please Enter a balance for CORPORATE account between $500.00 and $3000.00", "Initial Corporate Balance", "0.00")
If inputtedData = "" Then
MsgBox("User chose to Cancel calculation!")
Exit Sub
Else
initialBalanceCorporate = CType(inputtedData, Single)
If initialBalanceCorporate > 3000 Or initialBalanceCorporate < 500 Then MsgBox("Please enter a balance for CORPORATE account equal to or above $500.00 and no more than $3000.00", MsgBoxStyle.Critical, "Error")
End If
Loop Until initialBalanceCorporate >= 500 And initialBalanceCorporate <= 3000
Finally all the code is DEFINATELY NOT in the "btnMediaEstimatedFund" Procedure, as there is no calculation for the total values, neither is any consideration given to the fact that the calculation is for FUTURE years. in fact the KEY CALCULATION portions are missing!
What I mean is if you wish to generate a calculated figure for the year 2016, and now is 2013, then where is your accounting for the interest at 7% and 5%? I cannot see anywhere where it actually get calculated.
the subroutine which you "Dont know" how to create is no different from the subroutines you have created for your button/textbox/listbox events!
You pass parameters in and it does the calculation and if it is a SUB thats the end of it! and if it is a function then it returns a value or an object.
To create a Sub routine you give it a name an a list of parameters, if neccessary, you may have subroutines and functions without parameters but a function must ALWAYS return a value/object.
Sub ThisIsMySubroutine(MyParam1 as string, My Param2 as Object)
' code here
End Sub
Function ThisIsMyFunction(MyParam1 as string, My Param2 as Object) As Boolean
' code here
End Function
I'm sure you know already that the parameter and return data types can be any acceptable or recognized data types.
Update II
With regards to your last comment (beginning with.. Also, I am having one small..) If you swap the code and put your ORIGINAL code back, you will STILL have that same issue!
Okay, so one last more code sample and pointer.
So to stop your program (10% yours 90% mine hahaha) from asking for the input you can enclose it in an if statement...
If checkBoxSavings.Checked Then
Do
inputtedData = InputBox("Please Enter a balance for SAVINGS account between $500.00 and $3000.00", "Initial Savings Balance", "0.00")
If inputtedData = "" Then
MsgBox("User chose to Cancel calculation!")
Exit Sub
Else
initialBalanceSavings = CType(inputtedData, Single)
If initialBalanceSavings > 3000 Or initialBalanceSavings < 500 Then MsgBox("Please enter a balance for SAVINGS account equal to or above $500.00 and no more than $3000.00", MsgBoxStyle.Critical, "Error")
End If
Loop Until initialBalanceSavings >= 500 And initialBalanceSavings <= 3000
End If
If checkBoxCorporate.Checked Then
Do
inputtedData = InputBox("Please Enter a balance for CORPORATE account between $500.00 and $3000.00", "Initial Corporate Balance", "0.00")
If inputtedData = "" Then
MsgBox("User chose to Cancel calculation!")
Exit Sub
Else
initialBalanceCorporate = CType(inputtedData, Single)
If initialBalanceCorporate > 3000 Or initialBalanceCorporate < 500 Then MsgBox("Please enter a balance for CORPORATE account equal to or above $500.00 and no more than $3000.00", MsgBoxStyle.Critical, "Error")
End If
Loop Until initialBalanceCorporate >= 500 And initialBalanceCorporate <= 3000
End If
And for the interest here is a link for you,
http://math.about.com/od/businessmath/ss/Interest.htm
Its an EXCEPTIONALLY good explanation because it shows the interest over more than 1 year, which is what this part of your question is asking...
Please be aware of the current year, 2013. Now, the report is prepared in year 2013, but the balance should be calculated for your selected year (e.g., 2015, 2016, 2017). Think about the topic of repetition to determine the ending balance during your selected year

Related

Whats wrong with my error trapping function?

I have a program for buying shirts, I'm changing it so the error trapping happens through a function, so I deleted my previous error trapping, created the function, and tried it out. But somewhere I must of screwed up, because it's not working properly. I was following step by step the video guide from my class, but I can't find where I went wrong. I've been trying to figure it out for a few hours now but have gotten nowhere. Any help would be appreciated. What's happening is when I click Calculate or Next Sale, it will always give me my error message "Please enter a valid number" I've tried entering 0, 1, 25, 50, 51, 55, and 5a. It should give me an error message for 5a saying "Please enter a valid number", because it's not numeric. And it should give me the error message "Please enter a number from 1 to 50" for 0, 51, and 55. I couldn't even get that error message to work because every number I entered gave the "Please enter a valid number" error message. Where did I go wrong? Help me find the error please.
Here is the function:
Private Function CheckTextBox(ByVal TextBoxName As TextBox, ByVal Min As Single, ByVal Max As Single, ByVal IntCheck As Boolean) As Boolean
If Not IsNumeric(TextBoxName) Then
MessageBox.Show("Please enter a valid number", "Error", MessageBoxButtons.OK)
TextBoxName.Text = ""
TextBoxName.Focus()
Exit Function
End If
If Val(TextBoxName.Text) < Min Or Val(TextBoxName.Text) > Max Then
MessageBox.Show("Please enter a number from " & Min & " to " & Max, "Error", MessageBoxButtons.OK)
TextBoxName.Text = ""
TextBoxName.Focus()
Exit Function
End If
If IntCheck Then
If Val(TextBoxName.Text) <> Int(TextBoxName.Text) Then
MessageBox.Show("Please enter a whole number", "Error", MessageBoxButtons.OK)
TextBoxName.Text = ""
TextBoxName.Focus()
Exit Function
End If
End If
Return True
End Function
Here is the code for the Calculate button:
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
'Local Variable Declaration Section
Dim sngSalesTax As Single
Dim sngOrderTotal As Single
Dim intQuantity As Integer
Dim sngItemTotal As Single
'Data Input Section
If msngShippingCost = -1 Then
MessageBox.Show("Please choose a shipping method", "Error", MessageBoxButtons.OK) 'Displays an error messsage when no shipping method is chosen
Exit Sub 'Terminates the click event to allow shipping method to be chosen first
End If
If CheckTextBox(txtQuantity, 1, 50, True) = False Then
Exit Sub
End If
intQuantity = CInt(txtQuantity.Text) 'not sure if this line is needed?
'Calculation Section
sngItemTotal = msngItemPrice * intQuantity
msngSubtotal += sngItemTotal 'Calculates the subtotal
sngSalesTax = msngSubtotal * csngSalesTaxRate 'Calculates Sales Tax based on the sales tax rate constant
sngOrderTotal = msngSubtotal + sngSalesTax + msngShippingCost 'Calculates total for the sale
mintOrdersPlacedToday = mintOrdersPlacedToday + 1 'Calculates the number of orders placed today, adds one to the previous number
msngTotalOfOrdersToday = msngTotalOfOrdersToday + sngOrderTotal 'Calculates the Total of all the orders placed today
'Output section
lblShowSubTotal.Text = FormatCurrency(msngSubtotal) 'Displays the Sub Total
lblShowSalesTax.Text = FormatCurrency(sngSalesTax) 'Displays the Sales Tax
lblShowOrderTotal.Text = FormatCurrency(sngOrderTotal) 'Displays the Order Total
lblShowOrdersPlacedToday.Text = mintOrdersPlacedToday 'Displays the Orders placed today
lblShowTotalOfOrders.Text = FormatCurrency(msngTotalOfOrdersToday) 'Displays the Total of the Orders placed today
lblShowShippingCost.Text = FormatCurrency(msngShippingCost) 'Displays the total of the shipping cost
End Sub
And here is the code for the next item button:
Private Sub btnNextItem_Click(Sender As Object, e As EventArgs) Handles btnNextItem.Click
'Local Variable Declaration Section
Dim sngSalesTax As Single
Dim intQuantity As Integer
Dim sngItemTotal As Single
'Data Input Section
If CheckTextBox(txtQuantity, 1, 50, True) = False Then 'Uses the function to error trap exits sub if functions returns as false
Exit Sub
End If
intQuantity = CInt(txtQuantity.Text)
'Calculation Section
sngItemTotal = msngItemPrice * intQuantity 'Calculates item total
msngSubtotal += sngItemTotal 'Calculates the subtotal
sngSalesTax = msngSubtotal * csngSalesTaxRate 'Calculates Sales Tax based on the sales tax rate constant
'Output section
lblShowShippingCost.Text = ""
lblShowOrderTotal.Text = ""
lblShowSubTotal.Text = FormatCurrency(msngSubtotal) 'Displays the Sub Total
lblShowSalesTax.Text = FormatCurrency(sngSalesTax) 'Displays the Sales Tax
End Sub

Visual Basic code- Having trouble displaying the Total. New to VB

I have to write a program that calculates costs for a catering company. i have that part down, but whats stumping me is I have trouble displaying the total. What also is stumping me is that i have to make a summary button that adds everything up into a grand total from the previous calculations and display it in a message box. displaying and calculations aren't really my issues, but getting the data to calculate is.
Thank you
HERE's the code.
Const decPRIME_RIB As Decimal = 25.95D
Const decCHICKEN As Decimal = 18.95D
Const decPASTA As Decimal = 12.95D
Const decOPEN_BAR As Decimal = 25D
Const decWINE As Decimal = 8D
Const decBEER As Decimal = 10D
'Declare module-level variables for summary information.
Private TotalDollar As Decimal
Private AmountDue As Decimal
Private SubTotalDecimal As Decimal
Private TotalDecimal As Decimal
Private Guest As Integer
Private EventCountInteger As Integer
Private Sub CalcBtn_Click(sender As Object, e As EventArgs) Handles CalcBtn.Click
' Calculate and display the current amounts and add to totals.
Dim FoodChoiceDecimal As Decimal
Dim OpenBarDecimal As Decimal
Dim WineDecimal As Decimal
Dim DrinksDecimal As Decimal
' Find the price.
If PrimeRB.Checked Then
FoodChoiceDecimal = decPRIME_RIB
ElseIf ChickRB.Checked Then
FoodChoiceDecimal = decCHICKEN
ElseIf PastaRB.Checked Then
FoodChoiceDecimal = decPASTA
End If
If OpenCB.Checked Then
OpenBarDecimal = decOPEN_BAR
End If
If WineCB.Checked Then
WineDecimal = decWINE
End If
'Multiply price by number of guest and drink selection.
Try
DrinksDecimal = (OpenBarDecimal + WineDecimal)
AmountDue = (FoodChoiceDecimal + DrinksDecimal) * Guest
' display totals.
TotalLbl.Text = TotalLbl.ToString("C")
' Allow change for new event.
OpenCB.Enabled = False
WineCB.Enabled = False
ClearBtn.Enabled = True
SummaryBtn.Enabled = True
Catch NumberOfGuestsException As FormatException
MessageBox.Show("Number of Guests must be Numeric", _
"Data entry Error", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
End Try
End Sub
Private Sub SummaryBtn_Click(sender As Object, e As EventArgs) Handles SummaryBtn.Click
' Calculate total dollar amounts and number of events.
Dim MessageString As String
If EventCountInteger > 0 Then
' Calculate the summary sales totals.
TotalDollar += AmountDue
'Concatenate the message string.
MessageString = "Number of Events:" & EventCountInteger.ToString() _
& Environment.NewLine & Environment.NewLine _
& "Total Sales: " & TotalDollar.ToString("C")
MessageBox.Show(MessageString, "Sales Summary", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

Visual Basic loan interest and principal calculator

I'm trying to get the program to output the principal paid out to and the interest paid
towards a loan of $5000. No input is take its all been declared already.
Private Sub calButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calButton.Click
Dim monthlyPayments As Double
Dim bloanTotal As Double = 5000
Dim rate As Double = 0.005
Dim interest As Double
Dim toPrincipal As Double
Dim toInterest As Double
Dim counter As Integer
Do
'calculate the montly payments.
monthlyPayments =
Financial.Pmt(0.06 / 12, 12, 5000)
TextBox1.Text = monthlyPayments.ToString("C2")
counter = counter + 1 'add one to the counter
interest = bloanTotal * rate 'calculate interest rate from payment that will only count as interest
toInterest = monthlyPayments - interest 'amount of monthly payment going towards interest
toPrincipal = monthlyPayments - toInterest ' amount of monthly payment going towards principal
bloanTotal = bloanTotal - toPrincipal 'new balance after deducing principal from begining balance
Label2.Text = toPrincipal.ToString & " " &
toInterest.ToString &
ControlChars.NewLine ' concatinate principal and interest strings and create a new line
If counter = 12 Then 'exit loop once counter has reached 12 and loan amount has reached zero
Exit Do
End If
Loop
End Sub
I believe your problem is that the Financial.Pmt function is returning a negative number. Because this is accounting, you are telling the function you have recieved a 5000 loan (positive number) and you will be making payments (negative number). If you do this
monthlyPayments = Math.Abs(Financial.Pmt(0.06 / 12, 12, 5000))
then your calculations should work out.

VB.Net: Grade Calculator Program - Getting Ridiculous Values

I am attempting to create a grade calculator program and I am having some two problems:
Getting the right outputs (because I am getting ridiculous numbers) and
Getting my counters to work.
The basic form is basically one enters 7 input grades:
3 exams (weighed 15%, 20%, and 20% respectively)
A project (weighed 10%),
Assignments (weighed 20%),
Peer reviews (weighed 5%) ,
A programming language presentation (weighed 10%)
and the individual is supposed to get an output of their numeric grade, their letter grade, and two counters that count how many people got A's and F's.
For an example when I enter 3 exam grades: 82,87,91; Assignments: 94; Peer reviews: 100; programming language presentation: 90; and final project: 92,
I get a final numeric grade of 253.90 and a letter grade of F when it clearly should be a letter grade of A and numeric 89.90.
My counters also are not working properly because they aren't displaying the count, but I feel like I put it in the right place (displaying outputs). What exactly am I doing wrong here? Here's my code
Option Strict On
Public Class frmGradeCalculator
'declare Constants
Const EXAM1GRADE_WEIGHT As Decimal = 0.15D
Const EXAM2GRADE_WEIGHT As Decimal = 0.2D
Const EXAM3GRADE_WEIGHT As Decimal = 0.2D
Const HOMEWORKGRADE_WEIGHT As Decimal = 0.2D
Const HOMEWORKPEERREVIEW_WEIGHT As Decimal = 0.05D
Const LANGUAGEQUICKREFERENCE_WEIGHT As Decimal = 0.1D
Const FINALPROJECT_WEIGHT As Decimal = 0.1D
'Declare module variables
Dim mdecFinalNumericGrade As Decimal
Dim mstrFinalLetterGrade As String
Dim mintStudentsWithAs As Integer
Dim mintStudentsWithFs As Integer
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
'declare variables
Dim decExam1Grade As Decimal
Dim decExam2Grade As Decimal
Dim decExam3Grade As Decimal
Dim decHomeworkGrade As Decimal
Dim decPeerReviewGrade As Decimal
Dim decLanguageReferenceGrade As Decimal
Dim decFinalProjectGrade As Decimal
Dim decPercent As Decimal
'check for blanks
If (txtExam1Grade.Text) = "" Then
MessageBox.Show("You Can't Leave Exam 1 Blank")
Exit Sub
End If
'check for numeric
If IsNumeric(txtExam1Grade.Text) = False Then 'value is not numeric
MessageBox.Show("Please enter a numeric value for Exam 1!")
Exit Sub
End If
'check for blanks
If (txtExam2Grade.Text) = "" Then
MessageBox.Show("Please enter Exam 2!")
Exit Sub
End If
'check for everything else
If IsNumeric(txtExam2Grade.Text) = False Then 'Value is not numeric
MessageBox.Show("Please enter a numeric value for Exam 2!")
Exit Sub
End If
'check for blanks
If (txtExam3Grade.Text) = "" Then
MessageBox.Show("Please enter Exam 3!")
Exit Sub
End If
'check for numerics
If IsNumeric(txtExam3Grade.Text) = False Then
MessageBox.Show("Please enter a positive numeric value for Exam3!")
Exit Sub
End If
'check for blanks
If (txtHomeworkGrade.Text) = "" Then
MessageBox.Show("Please enter Homework Grade!")
Exit Sub
End If
'check for numerics
If IsNumeric(txtHomeworkGrade.Text) = False Then
MessageBox.Show("Please enter a numeric positive value for Homework Grade!")
Exit Sub
End If
'check for blanks
If (txtPeerReviewGrade.Text) = "" Then
MessageBox.Show("Please enter a Peer Review Grade!")
Exit Sub
End If
'check for numerics
If IsNumeric(txtPeerReviewGrade.Text) = False Then
MessageBox.Show("Please enter a numeric positive value for Peer Review Grade!")
Exit Sub
End If
'check for blanks
If (txtLanguageReferenceGrade.Text) = "" Then
MessageBox.Show("Please enter a Language Reference Grade!")
Exit Sub
End If
'check for numerics
If IsNumeric(txtLanguageReferenceGrade.Text) = False Then
MessageBox.Show("Please enter a numeric positive value for Language Reference Grade!")
Exit Sub
End If
'check for blanks
If (txtFinalProjectGrade.Text) = "" Then
MessageBox.Show("Please enter a Final Project Grade!")
Exit Sub
End If
'check for numerics
If IsNumeric(txtFinalProjectGrade.Text) = False Then
MessageBox.Show("Please enter a numeric positive value for Final Project Grade!")
Exit Sub
End If
'convert data types
decExam1Grade = Convert.ToDecimal(txtExam1Grade.Text)
decExam2Grade = Convert.ToDecimal(txtExam2Grade.Text)
decExam3Grade = Convert.ToDecimal(txtExam3Grade.Text)
decHomeworkGrade = Convert.ToDecimal(txtHomeworkGrade.Text)
decPeerReviewGrade = Convert.ToDecimal(txtPeerReviewGrade.Text)
decLanguageReferenceGrade = Convert.ToDecimal(txtLanguageReferenceGrade.Text)
decFinalProjectGrade = Convert.ToDecimal(txtFinalProjectGrade.Text)
mdecFinalNumericGrade = (decExam1Grade * EXAM1GRADE_WEIGHT) + _
(decExam2Grade * EXAM2GRADE_WEIGHT) + _
(decExam3Grade * EXAM3GRADE_WEIGHT) + _
(decHomeworkGrade * HOMEWORKGRADE_WEIGHT) + _
(decPeerReviewGrade * HOMEWORKPEERREVIEW_WEIGHT) + _
(decLanguageReferenceGrade + LANGUAGEQUICKREFERENCE_WEIGHT) + _
(decFinalProjectGrade + FINALPROJECT_WEIGHT)
'check for 0 or positive
If decExam1Grade < 0 Then
MessageBox.Show("Please enter a positive value or zero for Exam 1!")
Exit Sub
End If
'check for 0 or positive
If decExam2Grade < 0 Then
MessageBox.Show("Please enter a positive value or zero for Exam 2!")
Exit Sub
End If
'check for 0 or positive
If decExam3Grade < 0 Then
MessageBox.Show("Please enter a positive value or zero for Exam 3!")
Exit Sub
End If
'check for 0 or positive
If decHomeworkGrade < 0 Then
MessageBox.Show("Please enter a positive value or zero for Homework Grade!")
Exit Sub
End If
'check for 0 or positive
If decPeerReviewGrade < 0 Then
MessageBox.Show("Please enter a positive value or zero for Peer Review Grade!")
Exit Sub
End If
'check for 0 or positive
If decLanguageReferenceGrade < 0 Then
MessageBox.Show("Please enter a positive value or zero for Language Reference!")
Exit Sub
End If
'check for 0 or positive
If decFinalProjectGrade < 0 Then
MessageBox.Show("Please enter a positive value or zero for Final Project Grade!")
Exit Sub
End If
'make sure values are less than 100
If decExam1Grade > 100 Then
MessageBox.Show("Please enter a value thats 100 or less!")
End If
If decExam2Grade > 100 Then
MessageBox.Show("Please enter a value thats 100 or less!")
End If
If decExam3Grade > 100 Then
MessageBox.Show("Please enter a value thats 100 or less!")
End If
If decHomeworkGrade > 100 Then
MessageBox.Show("Please enter a value thats 100 or less!")
End If
If decPeerReviewGrade > 100 Then
MessageBox.Show("Please enter a value thats 100 or less!")
End If
If decLanguageReferenceGrade > 100 Then
MessageBox.Show("Please enter a value thats 100 or less!")
End If
If decFinalProjectGrade > 100 Then
MessageBox.Show("Please enter a value thats 100 or less!")
End If
'Determine grade per letter
Select Case decpercent
Case Is >= 89.5D
mstrFinalLetterGrade = "A"
mintStudentsWithAs += 1
Case Is >= 79.5D
mstrFinalLetterGrade = "B"
Case Is >= 69.5D
mstrFinalLetterGrade = "C"
Case Is >= 59.5D
mstrFinalLetterGrade = "D"
Case Else
mstrFinalLetterGrade = "F"
mintStudentsWithFs += 1
End Select
lblFinalLetterGrade.Text = mstrFinalLetterGrade
'display outputs
lblFinalNumericGrade.Text = mdecFinalNumericGrade.ToString("f2")
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'clear the texboxes and labels
txtExam1Grade.Clear()
txtExam2Grade.Clear()
txtExam3Grade.Clear()
txtHomeworkGrade.Clear()
txtPeerReviewGrade.Clear()
txtLanguageReferenceGrade.Clear()
txtFinalProjectGrade.Clear()
lblFinalLetterGrade.Text = ""
lblFinalNumericGrade.Text = ""
'setcursor back to top textbox
txtExam1Grade.Focus()
End Sub
Private Sub btnReset_Click(ByVal sende As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
'reset module level variables
mdecFinalNumericGrade = 0
mstrFinalLetterGrade = ""
mintStudentsWithAs = 0
mintStudentsWithFs = 0
End Sub
Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
'close the form
End
End Sub
Private Sub frmGradeCalculator_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Your final grade total is wrong because you're not multiplying the language presentation and final project by their weights, but adding the weight to the score:
Exam1 = 82 * .15 = 12.3
Exam2 = 87 * .20 = 17.4
Exam3 = 91 * .20 = 18.2
Assignments = 94 * .20 = 18.8
Peer Review = 100 * .05 = 5
Language Presentation = 90 + .10 = 90.1
Final Project = 92 + .10 = 92.1
Notice the addition (rather than multiplication) on the last two values. The total is 253.9.
Change the last two calculations for medcFinalNumericGrade to:
(decLanguageReferenceGrade * LANGUAGEQUICKREFERENCE_WEIGHT) + _
(decFinalProjectGrade * FINALPROJECT_WEIGHT)
You will always get an "F" because decpercent is never assigned a value, and therefore the Else Case is executed. Either assign decpercent a value, or use mdecFinalNumericGrade.
For example:
Select Case mdecFinalNumericGrade
instead of
Select Case decpercent
Once you fix the Select Case, your counts should work (unless you reset the form).

VB.NET Button Event Issue

I am having problem with a button the code of my button is.
Private Sub btnCalculateCosts_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCalculateCosts.Click
it handles:
' This Calculate Costs button click event handler edits the
' registration(costs) form to ensure it contains valid data.
' Then, after passing control to the business class, it
' displays the registration cost.
Dim objCourse As Course
Dim objCourseCostsFile As Course
Dim InputError As Boolean = False
' Is student ID entered properly
If Me.txtCorporateID.MaskFull = False Then
MessageBox.Show("Enter your Corporate ID in the Corporate ID box", "Error")
Me.txtCorporateID.Clear()
Me.txtCorporateID.Focus()
InputError = True
' Is student name entered properly
ElseIf Me.txtFirstName.TextLength < 1 Or _
Me.txtFirstName.Text < "A" Then
MessageBox.Show("Please enter your first name in the First Name box", "Error")
Me.txtFirstName.Clear()
Me.txtFirstName.Focus()
InputError = True
' Is number of units entered properly
ElseIf Me.txtLastName.TextLength < 1 Or _
Me.txtLastName.Text < "A" Then
MessageBox.Show("Please enter your last name in the Last Name box", "Error")
Me.txtLastName.Clear()
Me.txtLastName.Focus()
InputError = True
' Is number of units entered properly
ElseIf Not IsNumeric(Me.txtNumberOfDays.Text) Then
MessageBox.Show("Enter the units in the Number of Units box", "Error")
Me.txtNumberOfDays.Clear()
Me.txtNumberOfDays.Focus()
InputError = True
' Has 1-4 units been entered
ElseIf Convert.ToInt32(Me.txtNumberOfDays.Text) < 1 _
Or Convert.ToInt32(Me.txtNumberOfDays.Text) > 4 Then
MessageBox.Show("Units must be 1 - 4", "Error")
Me.txtNumberOfDays.Clear()
Me.txtNumberOfDays.Focus()
InputError = True
End If
' If no input error, process the registration costs
If Not InputError Then
If Me.radPreConferenceCourse.Checked = False Then
objCourse = New Course(txtCorporateID.Text, txtFirstName.Text, txtLastName.Text, txtNumberOfDays.Text)
Me.lblCosts.Visible = True
Me.lblCosts.Text = "Total Conference Costs Are: " & (objCourse.ComputeCosts()).ToString("C2")
Else
objCourse = New Course(txtCorporateID.Text, txtFirstName.Text, txtLastName.Text, txtNumberOfDays.Text, g)
Me.lblCosts.Visible = True
Me.lblCosts.Text = "Total Conference Costs Are: " & (objCourse.ComputeCosts()).ToString("C2")
....
Receiving the error:
Handles clause requires a WithEvents variable defined in the
containing type or one of its base types.
Where is btnCalculateCosts defined? – SLaks 14 hours ago