Creating a Shipping Charge Calculator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #16
    Originally posted by rents
    'Check the weight
    If (intWeight < 1) Or (intWeight > 20) Then
    lblErrorMessage .Text = "Our weight range is 1-20 kgs"
    lblErrorMessage .Visible = True
    Return
    End If

    'Check the distance
    If (decDistance < 10) Or (decDistance > 3000) Then
    lblErrorMessage .Text = "Our distance range is 10-3000 mi"
    lblErrorMessage .Visible = True
    End If


    this is what I've come up with for making sure the user enters number within my range.
    But when I test it, only the "our weight range.." error message shows up. I can't get the distance error message to show up at all.
    In fact even if I put a correct amount in for weight, it still gives me the error message about weight.
    What am I doing wrong?
    You're doing great, good of you to have patience. Try adding ElseIf into the mix. You may also need to get rid of Return. Give it a whirl with ElseIf first, then delete return if ElseIf alone does not work:

    Code:
            If (intWeight < 1) Or (intWeight > 20) Then
                lblErrorMessage.Text = "Our weight range is 1-20 kgs"
                lblErrorMessage.Visible = True
                Return
            ElseIf (decDistance < 10) Or (decDistance > 3000) Then
                lblErrorMessage.Text = "Our distance range is 10-3000 mi"
                lblErrorMessage.Visible = True
            End If
    Will test it here as well...

    Comment

    • rents
      New Member
      • Mar 2007
      • 26

      #17
      ok I re-did the code and stuck the validation in the appropriate boxes
      check it out

      Private Sub txtWeight_Valid ating(ByVal sender As Object, ByVal e As System.Componen tModel.CancelEv entArgs) Handles txtWeight.Valid ating


      'Validate the weight range

      If IsNumeric(txtWe ight.Text) Then
      Dim intWeight As Integer
      intWeight = CInt(txtWeight. Text)
      If intWeight < 1 Or intWeight > 20 Then
      lblErrorMessage .Text = "Our weight range is 1-20 kg"
      e.Cancel = True
      Else
      e.Cancel = False
      End If
      Else
      lblErrorMessage .Text = "Weight must be numeric"
      e.Cancel = True
      End If


      End Sub

      Private Sub txtDistance_Val idating(ByVal sender As Object, ByVal e As System.Componen tModel.CancelEv entArgs) Handles txtDistance.Val idating


      'Validate the Distance range

      If IsNumeric(txtDi stance.Text) Then
      Dim decDistance As Decimal
      decDistance = CDec(txtDistanc e.Text)
      If decDistance < 10 Or decDistance > 3000 Then
      lblErrorMessage .Text = "Our distance range is 10-3000 mi"
      e.Cancel = True
      Else
      e.Cancel = False
      End If
      Else
      lblErrorMessage .Text = "The distance must be numeric"
      e.Cancel = True
      End If


      End Sub
      End Class




      but now, if you put in an letter or go out of the range, you cannot clear anything with the clear button and you cannot exit the form at all. I had to do ctr-alt-del to get rid of it.
      Any ideas as to what may have happened???

      Comment

      • iburyak
        Recognized Expert Top Contributor
        • Nov 2006
        • 1016

        #18
        Guys sorry to interrapt.


        I would put folloing code in change event instead:

        [PHP]Private Sub txtWeight_Chang e()
        If Trim(txtWeight. Text) = "" Then Exit Sub

        If IsNumeric(txtWe ight.Text) And (Val(Trim(txtWe ight.Text)) > 0 And Val(Trim(txtWei ght.Text)) < 21) Then
        lblErrorMessage .Caption = ""
        Else
        lblErrorMessage .Caption "Weight must be numeric and between 1 and 20 kg", vbExclamation
        txtWeight.Text = ""
        txtWeight.SetFo cus
        End If

        End Sub[/PHP]

        But better instead of a label i would use a message box. People sometimes don't look at labels and can miss written warning. Message box is more obviouse in this case.

        [PHP]Private Sub txtWeight_Chang e()

        If Trim(txtWeight. Text) = "" Then Exit Sub

        If IsNumeric(txtWe ight.Text) And (Val(Trim(txtWe ight.Text)) > 0 And Val(Trim(txtWei ght.Text)) < 21) Then

        Else
        MsgBox "Weight must be numeric and between 1 and 20 kg", vbExclamation
        txtWeight.Text = ""
        txtWeight.SetFo cus
        End If

        End Sub[/PHP]

        Comment

        • rents
          New Member
          • Mar 2007
          • 26

          #19
          just in case you wanted to know, I ended up with a 95 out of 100 on this project
          *phew*!!
          thanks very much for all your help.
          keep your eyes peeled, I have another project due at the end of the week :)

          Comment

          • Dököll
            Recognized Expert Top Contributor
            • Nov 2006
            • 2379

            #20
            Originally posted by rents
            just in case you wanted to know, I ended up with a 95 out of 100 on this project
            *phew*!!
            thanks very much for all your help.
            keep your eyes peeled, I have another project due at the end of the week :)
            Fantastic, good going...

            As long as you post your work, your efforts, and are willing do some of the work, you should get sound, solid help...95 eh!, That's gold babee...

            Comment

            Working...