Am really glad i get someone to help with this , but the problem is am not really good on vb as am very new to it , can anyone please arrange it for me as it need to be then i will see what i can do with it . Then i will be able to start the project
Question is to change states name to 2 Letter and calculate tax rate for them as well.
California retail customers (State code = “CA”) are charged a sales tax on purchases – the California tax rate is 10%. Retail customers from New York (state code = “NY”) and Florida (state code = “FL”) are also taxed at a 5% tax rate.
Below is the code i have so far
Public Class Form1
Public Class State
Public Sub New(ByVal name As String, ByVal abbr As String, ByVal taxPercent As Decimal)
Me.Name = name
Me.Abbreviation = abbr
Me.TaxPercent = taxPercent
End Sub
Public Property Name As String
Public Property Abbreviation As String
Public Property TaxPercent As Decimal
End Class
Const U_P_S_DECIMAL As Decimal = 7D
Const SALES_TAX_RATE_SINGLE As Single = 0.1 '10 Percent Rate
'declare module-level variables
Private TotalQuantityInteger As Integer
Private TotalSalesDecimal As Decimal
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
'5 percent salses tex rate
Const SALES_TEX_RATE_SINGLE As Single = 0.05 '5 percent rate
Dim states As New List(Of State)
states.Add(New State("California", "CA", 10))
states.Add(New State("New York", "NY", 5))
states.Add(New State("Florida", "FL", 5))
For Each state As State In states
Console.WriteLine("State: {0} Abbrevation: {1} Tax: {2}%",
state.Name, state.Abbreviation, state.TaxPercent)
Next
'Declare variables
Dim SubDecimal, SalesTaxDecimal, TotalDueDecimal, TotalCostDecimal, ShippingCostDecimal 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
SalesTaxDecimal = Decimal.Round(Convert.ToDecimal(TotalCostDecimal * SALES_TEX_RATE_SINGLE), 2)
SubDecimal = SalesTaxDecimal + ShippingCostDecimal
'Total due is the subtotal minus discount amount plus sales tex
TotalDueDecimal = TotalCostDecimal + SubDecimal
If UPSRadioButton.Checked Then 'compute the shipping cost
ShippingCostDecimal = U_P_S_DECIMAL * QuantityInteger
End If
'Output - display output formatted as currency
SubtotalTextBox.Text = TotalCostDecimal.ToString("C")
TotalDueTextBox.Text = TotalDueDecimal.ToString("C")
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
End Try
End Sub
I have input the code i got on here but i dont know what to do to collect the data from textbox when the state is entered so that tax can be added to it . Any help will be appreciated. Am new to VB so i dont really know how everything works
For Each state As State In states
If state.name = TextBox.text then
'add your code here, you get the tax Rate with state.TaxPercent
'...
exit for
Next
Related
I need some help creating a mortgage loan calculator that allows the user to input the loan amount, loan years and loan rate and calculates the monthly mortgage payment and displays the amounts due for each month in a datagridview control. The problem is , i cannot seem to loop it using a for loop, i need to use the loop to display all the monthly payments but with my attempt it just repeats the same amounts for every month.Here is my code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim loanAmount As Double
Dim loanYears As Integer
Dim loanRate As Double
Dim monthlyPayment As Double
Dim numberofPayments As Integer
Dim monthlyInterest As Double
Dim decimalInterest As Double
Dim interestPaid As Double
Dim newBalance As Double
Dim principle As Double
Dim n As Integer
Dim Pmt As Integer = 1
loanAmount = Val(TextBox1.Text)
loanYears = Val(TextBox2.Text)
loanRate = Val(TextBox3.Text)
decimalInterest = loanRate / 100
numberofPayments = loanYears * 12
monthlyInterest = decimalInterest / 12
Label1.Text = monthlyPayment
For Pmt = 1 To numberofPayments
n = n + 1
If n = numberofPayments + 1 Then
Exit For
End If
monthlyPayment = loanAmount * monthlyInterest / (1 - (1 + monthlyInterest) ^ -numberofPayments)
interestPaid = loanAmount * monthlyInterest
principle = monthlyPayment - interestPaid
newBalance = loanAmount - principle
Me.DataGridView1.Rows.Add(n, Math.Round(monthlyPayment, 2), Math.Round(interestPaid, 2), Math.Round(principle, 2), Math.Round(newBalance, 2))
Next
End Sub
If someone could please help me out , it would be much appreciated.
Thank you
You need loanAmount = loanAmount - principle inside the For, or some other statement that tracks the principle balance and uses it in each iteration. It looks like you're trying to do that with the newBalance variable, but each iteration status over with loanAmount, which never decreases, so the values never change. I would suggest tracing through your math and making sure that your algorithm is actually performing the operations you desire.
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
So I have this program. It calculates the sale price of an item and displays the tax, subtotal, discount percent, which all works fine. The thing im trying to do is show 3 more textbox that accumulate the subtotal, discount amount, and the average discount.
Everytime I type anything in, the textboxs that are supposed to be accumulating are just displaying what the other boxs say, basically duplicating the boxs
Dim numberOfInvoices As Integer
Dim totalOfInvoices As Decimal
Dim invoiceAverage As Decimal
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim subtotal As Decimal = CDec(txtEnterSubtotal.Text)
Dim discountPercent As Decimal = 0.25D
Dim discountAmount As Decimal = Math.Round(subtotal * discountPercent, 2)
Dim invoiceTotal As Decimal = subtotal - discountAmount
Dim enterSubtotal As Decimal = Val(txtEnterSubtotal.Text)
Dim accumDiscount As Decimal = Val(txtAccumDiscAmount.Text)
Dim avgDiscount As Decimal = Val(txtAccumDiscAmount.Text)
Dim accumSubTotal As Decimal = Val(txtAccumSubtotal.Text)
txtSubtotal.Text = FormatCurrency(subtotal)
txtDiscountPercent.Text = FormatPercent(discountPercent, 1)
txtDiscountAmount.Text = FormatCurrency(discountAmount)
txtTotal.Text = FormatCurrency(invoiceTotal)
numberOfInvoices += 1
totalOfInvoices += invoiceTotal
invoiceAverage = totalOfInvoices / numberOfInvoices
txtNumberOfInvoices.Text = numberOfInvoices.ToString
txtTotalOfInvoices.Text = FormatCurrency(totalOfInvoices)
txtInvoiceAverage.Text = FormatCurrency(invoiceAverage)
'below is where I'm trying to accumulate everything entered....
txtAccumSubtotal.Text = FormatCurrency(accumSubTotal + subtotal)
txtAccumDiscAmount.Text = FormatCurrency(accumDiscount + discountAmount)
If avgDiscount = 0 Then
txtAvgDiscAmount.Text = FormatCurrency(discountAmount)
ElseIf avgDiscount > 0 Then
txtAvgDiscAmount.Text = FormatCurrency(avgDiscount / numberOfInvoices)
End If
txtEnterSubtotal.Text = ""
txtEnterSubtotal.Select()
'This is a comment
End Sub
Ignore my previous post, I was wrong. I found the problem.
VAL() on a percent or currency field will return 0. You have to take the "$" and "%" out of your string to do a VAL().
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.
The program should request the person’s occupation, the amount of the bill, and the percentage tip as input and pass this information to a Sub procedure to display the person and the tip. Title is gratuities, first line Person’s occupation, amount of the bill:, Percentage tip: Compute Tip, and show the tip. Im not sure how to approach it properly. Any help is greatly appreciated.
Public Class Form1
Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles btnCompute.Click
Dim Occupation As String = CStr(txtOccupation.Text)
Dim Bill As Double = CDbl(txtBill.Text)
Dim Tip As Double = CDbl(txtTip.Text)
lstOuput.Text = 'hmmmmm.....'
End Sub
End Class
lstOutput.Text = Bill * (1 + If(Tip<1,Tip,Tip/100))
Since you have assigned the Bill and Tip to double variables, you can assign the gratuity amount into another variable, or output it directly.
Dim Gratuity as Double = Bill * Tip
lstOutput.text = "Total Bill + Gratuity = " & string.format(Bill + Gratuity, "c")