Democratic Underground Latest Greatest Lobby Journals Search Options Help Login
Google

Visual Basic .NET Gurus help needed please

Printer-friendly format Printer-friendly format
Printer-friendly format Email this thread to a friend
Printer-friendly format Bookmark this thread
This topic is archived.
Home » Discuss » The DU Lounge Donate to DU
 
Hawkeye-X Donating Member (1000+ posts) Send PM | Profile | Ignore Thu Sep-18-03 02:04 PM
Original message
Visual Basic .NET Gurus help needed please
I'm having trouble trying to get this button to work
correctly:

This is part of my homework and I don't know if I screwed it
up or something.. 

This is the "Next Item Button" which is supposed to
validate the quantity, weight and price. Each must be present
and numeric. For any bad data, display a message box.
Calculate the charge for the current item and add the charge
and weight into the appropriate totals. Do not calculate
shipping and handling on the individual items, but rather,
calculate the shipping and handling in the entire order.

Here is what I have done so far:

 Dim mdecDue As Decimal
    Dim mdecTotal As Decimal
    Dim mdecWeightTotal As Decimal
    Dim mdecWeight As Decimal
    Dim mdecGrandTotal As Decimal
    Const mdecShip As Decimal = 0.25D
    Const mdecHandleLight As Decimal = 1D
    Const mdecHandleMed As Decimal = 3D
    Const mdecHandleHeavy As Decimal = 5D
    Const mdecTAX_RATE As Decimal = 0.08D

    Private Sub btnNext_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnNext.Click

        Dim intQuantity As Integer
        Dim decPrice As Decimal
        Dim decWeight As Decimal
        Dim decTotal As Decimal
        Dim decTaxTotal As Decimal
        Dim strMessage As String

        If txtQuantity.Text <> "" Then
            If IsNumeric(txtQuantity.Text) Then
                'Good Data, let's perform calculations
                Try
                    intQuantity = CInt(txtQuantity.Text)
                    decTotal = decPrice * intQuantity
                    decWeight = CInt(txtWeight.Text)
                    If decWeight < 10 Then
                        mdecWeightTotal = decTotal +
mdecHandleLight + (mdecShip * decWeight)
                    ElseIf decWeight >= 10 And decWeight
<= 100 Then
                        mdecWeightTotal = decTotal *
mdecHandleMed + (mdecShip * decWeight)

                    ElseIf decWeight > 100 Then
                        mdecWeightTotal = decTotal *
mdecHandleHeavy + (mdecShip * decWeight)
                    End If
                    mdecWeight += decWeight
                    lblDue.Text = FormatCurrency(mdecTotal)
                    lblShip.Text =
FormatCurrency(mdecWeightTotal)
                Catch
                    strMessage = "Calculation Error"
                    MessageBox.Show(strMessage,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End Try
            Else
                'Nonnumeric Data
                strMessage = "Nonnumeric data."
                MessageBox.Show(strMessage, "Data Entry
error", MessageBoxButtons.OK, MessageBoxIcon.Information)
                txtQuantity.Focus()
            End If
        Else 'Missing data
            strMessage = "Enter the quantity."
            MessageBox.Show(strMessage, "Data Entry
error", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub
Printer Friendly | Permalink |  | Top
Hawkeye-X Donating Member (1000+ posts) Send PM | Profile | Ignore Thu Sep-18-03 02:06 PM
Response to Original message
1. duhhh
Not done though, but added the following:

decPrice = cDec(txtPrice.text)

That should help resolve my calculation.
Printer Friendly | Permalink |  | Top
 
meegbear Donating Member (1000+ posts) Send PM | Profile | Ignore Thu Sep-18-03 02:08 PM
Response to Original message
2. Do your own homework!!!
Jeez buddy, how are you gonna learn?
Printer Friendly | Permalink |  | Top
 
sangh0 Donating Member (1000+ posts) Send PM | Profile | Ignore Thu Sep-18-03 02:16 PM
Response to Original message
3. So what's the problem?
Edited on Thu Sep-18-03 02:17 PM by sangh0
You have the code, but you don't say what's going wrong!


Printer Friendly | Permalink |  | Top
 
sangh0 Donating Member (1000+ posts) Send PM | Profile | Ignore Thu Sep-18-03 02:20 PM
Response to Reply #3
4. What's this?
If decWeight < 10 Then
mdecWeightTotal = decTotal +
mdecHandleLight + (mdecShip * decWeight)
ElseIf decWeight >= 10 And decWeight
<= 100 Then
mdecWeightTotal = decTotal *
mdecHandleMed + (mdecShip * decWeight)

ElseIf decWeight > 100 Then
mdecWeightTotal = decTotal *
mdecHandleHeavy + (mdecShip * decWeight)
End If


Is there a reason why you have "decTotal +" for the 1st IF condition, but "decTotal *" for the other conditions?
Printer Friendly | Permalink |  | Top
 
Hawkeye-X Donating Member (1000+ posts) Send PM | Profile | Ignore Thu Sep-18-03 02:21 PM
Response to Reply #4
6. I know.
Edited on Thu Sep-18-03 02:22 PM by HawkeyeX
That's where I messed up. I fixed that part, I think.

I took out the mdecTotal and put it in another line outside of the IF statement.

Printer Friendly | Permalink |  | Top
 
Hawkeye-X Donating Member (1000+ posts) Send PM | Profile | Ignore Thu Sep-18-03 02:20 PM
Response to Reply #3
5. Hmm..
I'm still working on it. If I'm in a nowheresville situation, I'll let you know.
Printer Friendly | Permalink |  | Top
 
sangh0 Donating Member (1000+ posts) Send PM | Profile | Ignore Thu Sep-18-03 02:22 PM
Response to Reply #5
7. You can use the F11 key
to step through the code, line by line.
Printer Friendly | Permalink |  | Top
 
DU AdBot (1000+ posts) Click to send private message to this author Click to view 
this author's profile Click to add 
this author to your buddy list Click to add 
this author to your Ignore list Thu Apr 25th 2024, 06:52 AM
Response to Original message
Advertisements [?]
 Top

Home » Discuss » The DU Lounge Donate to DU

Powered by DCForum+ Version 1.1 Copyright 1997-2002 DCScripts.com
Software has been extensively modified by the DU administrators


Important Notices: By participating on this discussion board, visitors agree to abide by the rules outlined on our Rules page. Messages posted on the Democratic Underground Discussion Forums are the opinions of the individuals who post them, and do not necessarily represent the opinions of Democratic Underground, LLC.

Home  |  Discussion Forums  |  Journals |  Store  |  Donate

About DU  |  Contact Us  |  Privacy Policy

Got a message for Democratic Underground? Click here to send us a message.

© 2001 - 2011 Democratic Underground, LLC