I'm trying to write a program for a vending machine. The program will ask the user to pick an option and it will calculate the change depending on the amount entered and the price of the product.
I can't get the program to calculate the change. I tried this but it doesn't work
Select Case choice
Case "1"
Console.WriteLine("enter amount")
amount = Console.ReadLine()
If amount < 0.6 Then
Console.WriteLine("not enough")
Else
change = amount - 0.6
End If
full code
Dim choice As String
Dim amount As Integer
Dim change As Integer
Sub Main(args As String())
Console.WriteLine("option 1: snickers price = 60p")
Console.WriteLine("option 2: coke price = £1")
Console.WriteLine("option 3")
Console.WriteLine("option 3")
Console.WriteLine("option 4")
Console.WriteLine("option 5")
Console.WriteLine("option 6")
Console.WriteLine("option 7")
Console.WriteLine("option 8")
Console.WriteLine("option 9")
Console.WriteLine("option 10")
choice = Console.ReadLine()
Select Case choice
Case "1"
Console.WriteLine("enter amount")
amount = Console.ReadLine()
If amount < 0.6 Then
Console.WriteLine("not enough")
Else
change = amount - 0.6
End If
Case "2"
Console.WriteLine("enter amount")
amount = Console.ReadLine()
If amount < 1 Then
Console.WriteLine("not enough")
Else
change = amount - 1
End If
End Select
Console.ReadLine()
End Sub
I see two issues in your code:
You are using Integer type for data that is decimal, so first of all you need to change the first two variables to Double
You are never showing the value that Change has; you calculate it but it is never shown on the screen. I have added a line that shows the change only if it is greater than 0.
Try something similar to the code I show below and see if you can continue from there:
Sub Main()
Dim choice As String
Dim amount As Double
Dim change As Double
Console.WriteLine("option 1: snickers price = 60p")
Console.WriteLine("option 2: coke price = £1")
Console.WriteLine("option 3")
Console.WriteLine("option 3")
Console.WriteLine("option 4")
Console.WriteLine("option 5")
Console.WriteLine("option 6")
Console.WriteLine("option 7")
Console.WriteLine("option 8")
Console.WriteLine("option 9")
Console.WriteLine("option 10")
choice = Console.ReadLine()
Select Case choice
Case "1"
Console.WriteLine("enter amount")
amount = Console.ReadLine()
If amount < 0.6 Then
Console.WriteLine("not enough")
Else
change = amount - 0.6
End If
Case "2"
Console.WriteLine("enter amount")
amount = Console.ReadLine()
If amount < 1 Then
Console.WriteLine("not enough")
Else
change = amount - 1
End If
End Select
If change > 0 then
Console.WriteLine("Change: " & change)
End If
End Sub
Related
I have a task to make a calculation of selling price and cost value.
I don't know have any idea to make a good coding for exception.
Private Sub ButtonCalculate_Click(sender As Object, e As EventArgs) Handles ButtonCalculate.Click
Dim SellingPrice As Double
Dim CostValue As Double
Dim Commission As Double
Dim CommissionRate As Double = 0.2
If Me.TextBoxSellingPrice.Text <> "" Or Me.TextBoxCostValue.Text <> "" Then
Try
SellingPrice = Double.Parse(TextBoxSellingPrice.Text)
CostValue = Double.Parse(TextBoxCostValue.Text)
'Calculation
Commission = CommissionRate * (SellingPrice - CostValue)
'Display
Me.TextBoxDisplay.Text = Me.TextBoxName.Text
Me.TextBoxCommission.Text = "RM" + Commission.ToString("F2")
Catch
MessageBox.Show("Wrong Input", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Else
MessageBox.Show("Please fill your data completely", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Output:
Figure 1
Using exception handling to check that data is correct isn't really the best practice. For a start, the performance of Try..Catch blocks is pretty poor compared to just using If..Then..Endif as there is a fair amount of stuff happening in the background with exceptions. In your case it wont make a major difference, but if the Try..Catch..End Try is in a loop, your program can take quite a performance hit.
There is little else to do other than to write some If..End If statements to validate your input data .. As other commenters had stated, using .TryParse is an exellent way to start things off ..
If Not Double.TryParse(TextBoxSellingPrice.Text, SellingPrice) Or Not Double.TryParse(TextBoxCostValue.Text, CostValue) Then
MessageBox.Show("Invalid input. Please enter positive numbers only")
Exit Sub
End If
If SellingPrice < CostValue Then
MessageBox.Show("Selling Price must be greater than cost")
Exit Sub
End If
If Not SellingPrice > 0 Or Not CostValue > 0 Then
MessageBox.Show("Selling price and cost must be >0")
Exit Sub
End If
'Calculation
Commission = CommissionRate * (SellingPrice - CostValue)
'Display
Me.TextBoxDisplay.Text = Me.TextBoxName.Text
Me.TextBoxCommission.Text = "RM" + Commission.ToString("F2")
You could also have a look at the ErrorProvider component
I want to ask how to do this based on a task i was given, i tried but it doesn't really work can anyone tell me why? Or even better if you could show me the correct version
The Task is:
Adapt the programme so the user must enter a quality for each diamond - Each diamond has a quality that is a whole number between 1 (low quality ) and 5 (high quality).
Here is the code (Sorry if its bad i am new to VB)
Can anyone perhaps show me how to fix, i've been told the mistakes, but honestly i am not sure how to actually fix them. :(
Dim Weight As Integer
Dim userValue As Boolean = True
Dim diamonds As Integer = 0
Console.WriteLine("Enter the weight of your diamond in grams")
Weight = Console.ReadLine
Dim Quality As Integer
Dim DiamondPrice As Integer
Console.WriteLine("Enter the quality of your diamond from 1 (low quality) to 5 (high quality)")
Quality = Console.ReadLine
If Quality = "1" Then
DiamondPrice = "100"
ElseIf Quality = "2" Then
DiamondPrice = "150"
ElseIf Quality = "3" Then
DiamondPrice = "200"
ElseIf Quality = "4" Then
DiamondPrice = "250"
ElseIf Quality = "5" Then
DiamondPrice = "300"
End If
Console.ReadLine()
Console.WriteLine("This diamond costs : " & Quality * )
Console.WriteLine("Would you like to price another Y/N?")
Console.ReadLine()
While userValue
Console.WriteLine("Enter the weight of the new diamond in grams")
Weight = Console.ReadLine
Console.WriteLine("This diamond costs : " & Weight * 350)
Console.WriteLine("Would you like to price another Y/N?")
userValue = Console.ReadLine.ToUpper().Trim() = "Y"
diamonds += 1
End While
Console.WriteLine("The total number of diamonds entered is : {0}", diamonds)
Console.ReadLine()
This is the third week of my intro to programming class and I'm stuck. I can get it to run I just can't enter more than 1 number. This is a vb console app.
Module Module1
Sub Main()
Dim highestNumber As Integer = -1000000000
Dim lowestNumber As Integer = 100000000
Dim userInput As Integer
Console.WriteLine("Input your numbers and when you are done enter -99.")
Console.WriteLine("The app will then give the highest and lowest numbers entered.")
userInput = Console.ReadLine()
While userInput <> "-99"
If userInput >= highestNumber Then
highestNumber = userInput
ElseIf userInput <= lowestNumber Then
lowestNumber = userInput
End If
End While
Console.WriteLine("The highest number you entered is: " & highestNumber)
Console.WriteLine("The lowest number you entered is: " & lowestNumber)
Console.ReadLine()
End Sub
End Module
You're only executing ReadLine once, before the loop starts, so you only get to enter one number. As it currently stands, if you don't enter -99 then you have an infinite loop since you cannot change userInput inside the loop.
You need to put a copy of userInput = Console.ReadLine() at the end of the While loop so that a new value can be entered and the logic will be re-executed.
Also, you might as well remove the = signs from your tests. No point changing the highest/lowest unless the new number is actual higher/lower.
Move this line inside your while loop
userInput = Console.ReadLine()
Here's my solution. It checks the input of the user, if it's not an integer they can try again or enter -99 and get out... You can also change how many numbers a user enters by changing a few places where it shows 2, or declare a variable and set it and then use it...
Public Sub Main()
Dim userInput As Integer = 0
Dim lstInteger As New List(Of Integer)
Console.WriteLine("Input your numbers and when you are done enter -99." & Environment.NewLine & "The app will then give the highest and lowest numbers entered.")
Do Until userInput = -99
If Integer.TryParse(Console.ReadLine(),userInput) AndAlso userInput <> -99 Then
lstInteger.Add(userInput)
If lstInteger.Count = 2 Then Exit Do
userInput = 0
If Integer.TryParse(Console.ReadLine(), userInput) AndAlso userInput <> -99 Then
lstInteger.Add(userInput)
If lstInteger.Count = 2 Then Exit Do
Else
If userInput = -99 Then Exit Do Else Console.WriteLine("Please enter a number.")
End If
Else
If userInput <> - 99 AndAlso userInput = 0 Then
Console.WriteLine("Please enter a number.")
Else
Exit Do
End If
End If
Loop
If lstInteger.Count = 2 Then
Console.WriteLine("The highest number you entered is: " & lstInteger.Max.ToString)
Console.WriteLine("The lowest number you entered is: " & lstInteger.Min.ToString)
End If
Console.ReadLine()
End Sub
Am having problem with shipping extra cost in vb 2010 , The question is to calculate the extra handling charge of $5.00 per part for an oversize container (the Oversize Container CheckBox is checked). Below is the code i have worked on for the shipping rate . I have define oversize as constant but i cant get it to work
What we are told to do is to make sure when the oversizedcheckbox is checked it should calculate the oversize amount which is $5 per unit and it should be added to any shipping charges that has been selected . In my case i have 4 shipping which is
ups $7 per unit , us postal air $8.5 per unit , fedex ground $9.2 per unit and fedex air $12 per unit
Public Class Lab5
'ship mode constants
Const U_P_S_DECIMAL As Decimal = 7D
Const FED_EX_AIR_DECIMAL As Decimal = 12D
Const FED_EX_GROUND_DECIMAL As Decimal = 9.25D
Const US_POSTRAL_AIR_DECIMAL As Decimal = 8.5D
Const SALES_TAX_RATE_SINGLE As Single = 0.1 '10 Percent Rate
'declear module-level variables
Private TotalQuantityInteger As Integer
Private TotalSalesDecimal As Decimal
Private Sub ComputeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComputeButton.Click, ComputeToolStripMenuItem.Click
Try
Dim TotalCostDecimal, ShippingCostDecimal, SalesTaxDecimal, OversizeDecimal, TotalDueDecimal As Decimal
'Declare variables and convert value from textbox controls to memory
Dim PriceDecimal As Decimal = Decimal.Parse(PriceTextBox.Text, Globalization.NumberStyles.Currency)
Dim QuantityInteger As Integer = Integer.Parse(QuantityTextBox.Text, Globalization.NumberStyles.Number)
'Process - Compute values
'Subtotal = price times the quantity of books
TotalCostDecimal = PriceDecimal * QuantityInteger
'Sales tex = sales tax rate times the subtotal minus discount amount
If RetailCheckBox.Checked Then
SalesTaxDecimal = Decimal.Round(Convert.ToDecimal(TotalCostDecimal * SALES_TAX_RATE_SINGLE), 2)
End If
If CustomerIDMaskedTextBox.MaskCompleted = False Then
'incomplete telephone number
MessageBox.Show("Incomplete or missing CustomerID", "CustomerID Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
CustomerIDMaskedTextBox.Focus()
CustomerIDMaskedTextBox.SelectAll()
ElseIf NameTextBox.Text.Trim = String.Empty Then
'Customer name is required
MessageBox.Show("Customer Name is required", "Customer Name Missing Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
NameTextBox.Focus()
NameTextBox.SelectAll()
ElseIf StateTextBox.Text.Trim = String.Empty Then
'Shipping address required
MessageBox.Show("State is required", "State Missing Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
StateTextBox.Focus()
StateTextBox.SelectAll()
ElseIf PartTextBox.Text.Trim = String.Empty Then
'Missing Part Number Required
MessageBox.Show("Part Number is missing", "Part Number Missing Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
PartTextBox.Focus()
PartTextBox.SelectAll()
ElseIf DescriptionTextBox.Text.Trim = String.Empty Then
'Description is Required
MessageBox.Show("Product Description is missing", "Product Description Missing Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
DescriptionTextBox.Focus()
DescriptionTextBox.SelectAll()
ElseIf IsNumeric(PriceTextBox.Text) = False Then
'the purchase price textbox must contain a numeric value
MessageBox.Show("Price must contain a numeric value", "Price Not Numeric Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
PriceTextBox.Focus()
PriceTextBox.SelectAll()
ElseIf IsNumeric(QuantityTextBox.Text) = False Then
'the Quantity purchased Testbox must contain a numeric value
MessageBox.Show("Quantity must be input", "Quantity Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
QuantityTextBox.Focus()
QuantityTextBox.SelectAll()
ElseIf Decimal.Parse(QuantityTextBox.Text, Globalization.NumberStyles.Number) < 0 Then
'the quantity purchased must be greater than zero
MessageBox.Show("The quantity must be greater than zero", "Quantity Purchased not greater than zero Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
End If
'Shipping cost
If UPSRadioButton.Checked Then 'compute the shipping cost
ShippingCostDecimal = U_P_S_DECIMAL * QuantityInteger
ElseIf FedExAirRadioButton.Checked Then
ShippingCostDecimal = FED_EX_AIR_DECIMAL * QuantityInteger
ElseIf FedExGroundRadioButton.Checked Then
ShippingCostDecimal = FED_EX_GROUND_DECIMAL * QuantityInteger
ElseIf USPostalAirRadioButton.Checked Then
ShippingCostDecimal = US_POSTRAL_AIR_DECIMAL * QuantityInteger
End If
'Compute TotalDue
TotalDueDecimal = SalesTaxDecimal + ShippingCostDecimal + TotalCostDecimal
'Data computed output
SubtotalTextBox.Text = TotalCostDecimal.ToString("C")
TotalDueTextBox.Text = TotalDueDecimal.ToString("C2")
SalesTaxTextBox.Text = SalesTaxDecimal.ToString("N")
ShippingCostTextBox.Text = ShippingCostDecimal.ToString("N")
'Accumulate total sales and total books sold
TotalQuantityInteger += QuantityInteger
TotalSalesDecimal += TotalDueDecimal
Catch ex As Exception
MessageBox.Show("unexpected error", "Compute Button Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
As mentioned in my comment....
You say you need to add an oversize rate of $5 but this line
OversizeDecimal = ShippingCostDecimal * OVERSIZE_RATE_DECIMAL
seem to be multiplying by 5
Try
OversizeDecimal = ShippingCostDecimal + (OVERSIZE_RATE_DECIMAL * QuantityInteger)
I finally figure it out myself
Public Class Lab5
'ship mode constants
Const U_P_S_DECIMAL As Decimal = 7D
Const FED_EX_AIR_DECIMAL As Decimal = 12D
Const FED_EX_GROUND_DECIMAL As Decimal = 9.25D
Const US_POSTRAL_AIR_DECIMAL As Decimal = 8.5D
Const OVERSIZE_RATE_DECIMAL As Decimal = 5D
Const SALES_TAX_RATE_SINGLE As Single = 0.1 '10 Percent Rate
'Oversized Handling Charges
If OversizedCheckBox.Checked Then
ShippingCostDecimal = QuantityInteger * (OVERSIZE_RATE_DECIMAL + U_P_S_DECIMAL)
ElseIf OversizedCheckBox.Checked Then
ShippingCostDecimal = QuantityInteger * (OVERSIZE_RATE_DECIMAL + FED_EX_AIR_DECIMAL)
ElseIf OversizedCheckBox.Checked Then
ShippingCostDecimal = QuantityInteger * (OVERSIZE_RATE_DECIMAL + FED_EX_GROUND_DECIMAL)
ElseIf OversizedCheckBox.Checked Then
ShippingCostDecimal = QuantityInteger * (OVERSIZE_RATE_DECIMAL + US_POSTRAL_AIR_DECIMAL)
End If
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