Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

VB Help- Beginner here what am I doing wrong?

Programming Visual Basic Coding VB Help Beginner Need a Genius!

  • Please log in to reply

#1
VB- clueless

VB- clueless

    New Member

  • Member
  • Pip
  • 1 posts

Finishing up a mandatory class for graduation and have been working on my final for 2 days!!! I have to create a form that calculates the amount due for an order .....I am VB challenged and need some assistance to get this to work. Every time I run the program the total due will not display in the summary screen..... Any help would be greatly and I mean greatly appreciated!!!!!

 

 

 

 

 

Public Class MainForm
    Const HANDLING_0_TO_10_Decimal As Decimal = 1D
    Const HANDLING_10_TO_100_Decimal As Decimal = 3D
    Const HANDLING_100_PLUS_Decimal As Decimal = 5D
    Const TAX_RATE_Decimal As Decimal = 0.08D          'Rate for CA sales
    Const SHIPPING_CHARGE_Decimal As Decimal = 0.25D    'Per pound charge
    Friend amountDueTotalDecimal, weightTotalDecimal, _
        taxDecimal, totalDueDecimal, shippingHandlingDecimal As Decimal


    Private Function ShippingHandling(ByVal weightTotalDecimal As Decimal) As Decimal
        'Calculate shipping and handling
        Dim handlingDecimal, shippingDecimal As Decimal

        Select Case weightTotalDecimal
            Case 1 To 9
                handlingDecimal = HANDLING_0_TO_10_Decimal
            Case 10 To 100
                handlingDecimal = HANDLING_10_TO_100_Decimal
            Case Is > 100
                handlingDecimal = HANDLING_100_PLUS_Decimal
        End Select
        shippingDecimal = weightTotalDecimal * SHIPPING_CHARGE_Decimal
        Return shippingDecimal + handlingDecimal
    End Function

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click

    'Exit from the form.
    Me.Close()


End Sub

Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click

    'Show the About form
    Dim About As New AboutForm
    About.Show()


End Sub

Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click

        'Clear all entries and reset all counters and accumulators for this customer.

        With Me
            .StreetTextBox.Clear()
            .CityTextBox.Clear()
            .StateTextBox.Clear()
            .ZipTextBox.Clear()
            .DescriptionTextBox.Clear()
            .QuantityTextBox.Clear()
            .WeightTextBox.Clear()
            .PriceTextBox.Clear()

            'Enable the customer information text boxes.
            .NameTextBox.Enabled = True
            .StreetTextBox.Enabled = True
            .CityTextBox.Enabled = True
            .StateTextBox.Enabled = True
            .ZipTextBox.Enabled = True
            .DescriptionTextBox.Enabled = True
            .QuantityTextBox.Enabled = True
            .WeightTextBox.Enabled = True
            .PriceTextBox.Enabled = True


            amountDueTotalDecimal = 0
            weightTotalDecimal = 0
            taxDecimal = 0
            totalDueDecimal = 0
            shippingHandlingDecimal = 0

            With .NameTextBox
                .Clear()
                .Focus()
            End With
        End With
    End Sub
    Private Sub AddThisItemToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddThisItemToolStripMenuItem.Click

        'Process the current item and add to the appropriate total
        Dim QuantityInteger As Decimal
        Dim weightDecimal, priceDecimal, itemAmountDecimal As Decimal
        Dim messageString As String

        With Me
            'Verify that all data is valid
            Try

            Catch ex As Exception

            End Try
            QuantityInteger = Decimal.Parse(QuantityTextBox.Text)
            Try
                weightDecimal = Decimal.Parse(.WeightTextBox.Text)
                Try
                    priceDecimal = Decimal.Parse(.PriceTextBox.Text)

                    'Perform calculations
                    weightDecimal *= QuantityInteger
                    itemAmountDecimal = QuantityInteger * priceDecimal
                    amountDueTotalDecimal += itemAmountDecimal
                    weightTotalDecimal += weightDecimal


                    .DescriptionTextBox.Clear()
                    .QuantityTextBox.Clear()
                    .WeightTextBox.Clear()
                    .PriceTextBox.Clear()
                    .DescriptionTextBox.Focus()

                    'Disable the customer information until the user chooses to clear the data.
                    .NameTextBox.Enabled = False
                    .StreetTextBox.Enabled = False
                    .CityTextBox.Enabled = False
                    .StateTextBox.Enabled = False
                    .ZipTextBox.Enabled = False


                Catch priceException As FormatException
                    messageString = "Please input a valid number for the price."
                    MessageBox.Show(messageString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    With .PriceTextBox
                        .Focus()
                        .SelectAll()
                    End With
                End Try
            Catch weightException As FormatException
                messageString = "Please input a valid number for the weight."
                MessageBox.Show(messageString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                With .WeightTextBox
                    .Focus()
                    .SelectAll()
                End With
            End Try
        End With
    End Sub


    Private Sub UpdateSummaryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateSummaryToolStripMenuItem.Click

        'Display the summary form

        With Me
            'Calculate shipping
            shippingHandlingDecimal = ShippingHandling(weightTotalDecimal)

            'Calculate sales tax
            If .StateTextBox.Text.ToUpper = "CA" Then
                taxDecimal = amountDueTotalDecimal * TAX_RATE_Decimal
            End If

            'Calculate total due
            totalDueDecimal = amountDueTotalDecimal + taxDecimal + shippingHandlingDecimal

            'Disable the order information.  Additional items would cause the shipping charges to be incorrect.
            .DescriptionTextBox.Enabled = False
            .QuantityTextBox.Enabled = False
            .WeightTextBox.Enabled = False
            .PriceTextBox.Enabled = False
        End With
        SummaryForm.ShowDialog()
    End Sub
End Class


  • 0

Advertisements


#2
ident

ident

    Member

  • Member
  • PipPipPip
  • 745 posts

Ok your code needs major work but we will get to that later. The question you currently ask is clear as day. Why would it be displayed? All you do is show the default instance of a form(which is a major no no any way). How does that form know any thing about the form with the calculations?


  • 0






Similar Topics


Also tagged with one or more of these keywords: Programming, Visual Basic, Coding, VB, Help, Beginner, Need a Genius!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP