October 11th, 2013, 09:19 AM
Help with Arrays in Murachs Visual Basic
Okay so im new to adding arrays and using indexes in visual basic and also quite new to visual basic. Im trying to complete a problem out of a book that has to do with adding a 5 element array and also a module variable that uses an index to work with the array.
Public Class frmInvoiceTotal
Dim invTotals(4) As Decimal
Private Sub btnCalculate_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim subtotal As Decimal = CDec(txtSubtotal.Text)
Dim discountPercent As Decimal
If txtCustomerType.Text = "R" Then
If subtotal < 100 Then
discountPercent = 0
ElseIf subtotal >= 100 AndAlso subtotal < 250 Then
discountPercent = 0.1D
ElseIf subtotal >= 250 Then
discountPercent = 0.25D
ElseIf txtCustomerType.Text = "C" Then
If subtotal < 250 Then
discountPercent = 0.2D
discountPercent = 0.3D
discountPercent = 0.4D
Dim discountAmount As Decimal = subtotal * discountPercent
Dim invoiceTotal As Decimal = subtotal - discountAmount
txtDiscountPercent.Text = FormatPercent(discountPercent, 1)
txtDiscountAmount.Text = FormatCurrency(discountAmount)
txtTotal.Text = FormatCurrency(invoiceTotal)
Private Sub btnExit_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnExit.Click
That is the code so far. I need to add code that adds the invoice total to the next element in the array each time the calculate button is clicked. Add code that displays all the invoice totals in the array in a message box when the user click the exit button using a For Each loop. Also if a element in the array in equal to 0 we need to ignore it. So any value in the array greater than 0 is valid. We also need to sort the invoices total in the array.
Any guidance would be greatly appreciated.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!