CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2013

    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
    End If
    ElseIf txtCustomerType.Text = "C" Then
    If subtotal < 250 Then
    discountPercent = 0.2D
    discountPercent = 0.3D
    End If
    discountPercent = 0.4D
    End If

    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)

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles btnExit.Click
    End Sub

    End Class

    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.

  2. #2
    Join Date
    Jul 2005

    Re: Help with Arrays in Murachs Visual Basic

    It could be better if the moderator move to vb.net forum

    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  3. #3
    Join Date
    Jul 2001
    Sunny South Africa

    Re: Help with Arrays in Murachs Visual Basic

    [ Moved ]

  4. #4
    Join Date
    Apr 2012

    Re: Help with Arrays in Murachs Visual Basic

    Well arrays are fixed in VB.Net. When you need to add items to a list its generally recommended you use a List(Of T). It has an Add method.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.