VB programming help

Discussion in 'OT Technology' started by mikeeb13, Oct 10, 2005.

  1. mikeeb13

    mikeeb13 New Member

    Joined:
    Feb 16, 2005
    Messages:
    15,204
    Likes Received:
    0
    Location:
    cowlifornia
    Can anyone help me with this.. My program is supposed to do calculations based on the 2 text box inputs, but if the 2 text box inputs arent numeric and bigger than 0 i want it to display an error message and not calculate. It's giving me the error box, but still going through the calculations...can anyone give me some help or point out what im doing wrong here...

    here's the code for the "Calculate" button


    'Dim Statements
    Dim decCarsSalesPrice As Decimal
    Dim decTradeIn As Decimal
    Dim decAccessoriesFinish As Decimal
    Dim decSalesTax As Decimal
    Dim decSubtotal As Decimal
    Dim decAmountDue As Decimal

    'Required Field Test - Name not blank
    If IsNumeric(TxtCarSalesPrice.Text) = False Then
    'Data has to be numeric test
    MessageBox.Show("Price has to be a number", "Price Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    TxtCarSalesPrice.Focus()

    ElseIf
    CDec(TxtCarSalesPrice.Text) < 0 Then
    'Range test fails
    MessageBox.Show("Price must be a positive number", "Price Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    TxtCarSalesPrice.Focus()

    ElseIf IsNumeric(TxtTradeIn.Text) = False Then
    'Range test fails
    MessageBox.Show("Trade in value has to be a number", "Trade In Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    TxtCarSalesPrice.Focus()

    ElseIf CDec(TxtTradeIn.Text) < 0 Then
    'Range test fails
    MessageBox.Show("Trade in value must be a positive number", "Trade in Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    TxtCarSalesPrice.Focus()
    End If

    'Convert to numeric values
    If IsNumeric(TxtCarSalesPrice.Text) And IsNumeric(TxtTradeIn.Text) Then

    If
    ChkStereoSystem.Checked Then
    decAccessoriesFinish += mdecStereoSystem
    End If

    If
    ChkLeatherInterior.Checked Then
    decAccessoriesFinish += mdecLeatherInterior
    End If

    If
    ChkComputerNavigation.Checked Then
    decAccessoriesFinish += mdecComputerNavigation
    End If

    If
    RadStandard.Checked Then
    decAccessoriesFinish += mdecStandard
    End If

    If
    RadPearlized.Checked Then
    decAccessoriesFinish += mdecPearlized
    End If

    If
    RadCustomizedDetailing.Checked Then
    decAccessoriesFinish += mdecCustomizedDetailing
    End If

    End If

    Try

    'Show Accessories and Finish price
    LblAccessories.Text = FormatCurrency(decAccessoriesFinish)

    'Calculate Sales Tax for Car's Sales Price and Accessories & Finish
    decCarsSalesPrice = CDec(TxtCarSalesPrice.Text)
    decSalesTax = (decCarsSalesPrice + decAccessoriesFinish) * mdecTaxRate

    'Formats Cars Sales Price
    TxtCarSalesPrice.Text = FormatCurrency(decCarsSalesPrice)

    'Formats Trade In Value
    TxtTradeIn.Text = FormatCurrency(decTradeIn)

    'Show Sales Tax price
    LblSalesTax.Text = FormatCurrency(decSalesTax)

    'Calculate Subtotal
    decSubtotal = decCarsSalesPrice + decAccessoriesFinish + decSalesTax

    'Show Subtotal Price
    LblSubtotal.Text = FormatCurrency(decSubtotal)

    'Calculate Amount Due
    decTradeIn = CDec(TxtTradeIn.Text)
    decAmountDue = decSubtotal + decTradeIn

    'Display Amount Due
    LblAmountDue.Text = FormatCurrency(decAmountDue)

    Catch

    End
    Try

    End
    Sub
     
  2. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    after displaying each error message you need to have an "exit sub" line so the function no longer executes, but exits.
     

Share This Page