Creating a Shipping Charge Calculator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rents
    New Member
    • Mar 2007
    • 26

    Creating a Shipping Charge Calculator

    Hello everybody. I am a complete noob in writing VB code. I don't have a problem drawing a form, but when it comes to code. I am lost.
    I have a user interface design class and we have a small project due. I was wondering if anyone could give me some mega help.
    The project we have to complete is the following:

    The Fast Freight Shipping Company charges the rates listed in the following table:

    Weight of the Package (in kilograms) / Shipping rate per Mile
    2kg or less / $0.01
    over 2kg, but not more than 6kg /$0.015
    over 6kg, but not more than 10kg /$0.02
    over 10kg, but not more than 20kg / $0.025

    Create an application that allows the user to enter the weight of the package and the distance it is to be shipped, and then displays the charges.

    Input validation: Do not accept values of 0 or less for the weight of the package. Do not accept weights of more thann 20 kg(this is the maximum weight the company will ship) Do not accept distances of less than 10 miles or more than 3000 miles. These are the company's minimum and maximum shipping distances. Use exception handling to check for non-numeric data.



    I'm knd of asking for someone to pretty much write the code I would need to make this function properly. I will be trying to mess around with it while I wait for any response. Thanks very much in advancne
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Ahhh, the good old days :-) Hello rents!

    I have had similar projects in the past..I am sure likewise for members here. Would you be able to post what you have thus far so one can take a look?

    It'd be helpful to you and to this forum if in need of a quick response...

    When is this due?

    Dököll

    Comment

    • rents
      New Member
      • Mar 2007
      • 26

      #3
      Dokoll,

      Thanks for the response. So far, I have only created the form itself. With buttons and labels and what not. The only code I have entered is for the exit button to work :)

      I'm not exactly sure what you like to me show on here, so I just copied and pasted the part where the code is placed.

      Private Sub Label1_Click(By Val sender As System.Object, ByVal e As System.EventArg s) Handles Label1.Click

      End Sub

      Private Sub Label2_Click(By Val sender As System.Object, ByVal e As System.EventArg s) Handles Label2.Click

      End Sub

      Private Sub Label3_Click(By Val sender As System.Object, ByVal e As System.EventArg s) Handles Label3.Click

      End Sub

      Private Sub btnClear_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnClear.Click

      End Sub

      Private Sub btnExit_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles btnExit.Click
      'Exit Calculator

      Me.Close()

      End Sub

      Private Sub txtWeight_TextC hanged(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles txtWeight.TextC hanged

      End Sub

      Private Sub txtDistance_Tex tChanged(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles txtDistance.Tex tChanged

      End Sub

      Private Sub lblCost_TextCha nged(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles lblCost.TextCha nged

      End Sub

      Private Sub btnCalculate_Cl ick(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnCalculate.Cl ick

      End Sub
      End Class

      i guess this would give you an idea as to what I have on the form. I feel a little silly not knowing even where to begin to write code. I mean I know where it goes, but just confused as to what to type in first.

      If you need more info from me, please let me know. This project is due on Saturday, but I'd like to have it finished by at least Friday.
      Thanks

      Comment

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

        #4
        OK, Rents...Thanks for your prompt response. I have a simple code you can add to the mix. Let me fetch it and will post. If this does not work, I'll let someone else take a stab at it. In a bit!

        Comment

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

          #5
          Also, perhaps you can reduce your button clicks to at least a couple! I just noticed you have buttons for almost every event. Is this necessary? It's likely the project at hand wants you to submit in this fashion and that's ok, if this is a fact, please ignore my comment here.

          To begin, and assuming this is what you hope to achieve:

          (1) you will need to dimension a place holder for your dollar amounts as currency (i.e. Textbox that will carry $0.00...)
          (2) you will also need to dimension a place holder as integer (i.e. Textbox that should carry kg units and so on...

          Please stay tuned while I fetch for code.

          Comment

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

            #6
            rents, my friend, I do not have good news, but no worries. My small program is almost 5 years old, hadn't touch it since graduation. Anyway, the code is not working properly. I could not find you a good tutorial on this, so I will attempt to help you from memory:

            (1) Looks like you will need to tell the program to look for instances where a certain textbox/label has greater or equal to 10 miles (a select case or if statement should help you deal with this).

            (2) You will also need to tell VB you want not more but less than 3000 miles, you can add this in the same select or if statement, or a loop of some sort

            (3) VB must know you will not accept more than 20kg, add to your statements as well

            (4) As mentioned before, you will need to dimension the currency textbox/label as currency so VB know amounts will be added.

            Here is part of my old code that works:

            Code:
                Dim num_one As Currency ''Specific to a textbox called Price.Text
                Dim num_two As Integer    'Specific to a textbox called Items.Text
                Dim Total_results_num As Currency ''Specific to a label called Total_results
            
                num_one = Int(Price.Text)
                num_two = Int(Items.Text)
                
                Total_results_num = num_one + num_two 'calculates amount with items
                Total_results = Total_results_num
            Give this one a whirl, see what pops up.

            Good luck!

            Comment

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

              #7
              Whoops! I found out the problem, it works now. Since it is a label, I must add .Caption to it, thus:

              Code:
              Private Sub Total_Click()                        'total button calculator
                  
                  Dim num_one As Currency                 'see textbox named Price.Text
                  Dim num_two As Integer                    'see textbox named Price.Text
                  Dim Total_results_num As Currency   'see label named Total_results.Caption
                 
                  num_one = Int(Price.Text)
                  num_two = Int(Items.Text)
                  Total_results_num = num_one + num_two
                  Total_results.Caption = Total_results_num
                  
                  
              End Sub
              There, try this. You'll have to do most of the work, Hopefuly this gets you started right :-)

              Comment

              • rents
                New Member
                • Mar 2007
                • 26

                #8
                Dokoll

                Thanks for all the responses, but I still do not understand what is going on.
                Like what exact code should I put in where?

                Comment

                • rents
                  New Member
                  • Mar 2007
                  • 26

                  #9
                  Private Sub Total_Click() 'total button calculator

                  Dim num_one As Currency 'see textbox named Price.Text
                  Dim num_two As Integer 'see textbox named Price.Text
                  Dim Total_results_n um As Currency

                  ok..for this part..where it says Dim num_one As Currency..

                  what should I put in for mine..for my weight textbox (txtweight)

                  Dim decWeight As ???? (it's supposed to run in kg)

                  Comment

                  • rents
                    New Member
                    • Mar 2007
                    • 26

                    #10
                    ok, I've kind of figured out what I am doing. But now I've run into a problem.
                    I have these IF statements in my calculate button


                    If IsNumeric(txtWe ight.Text) = False Then
                    lblErrorMessage .Text = "Weight must numeric"
                    lblErrorMessage .Visible = True
                    Return
                    End If

                    If IsNumeric(txtDi stance.Text) = False Then
                    lblErrorMessage .Text = "Distance must be numeric"
                    lblErrorMessage .Visible = True
                    Return
                    End If

                    but when I test the Distance with some letter, the error label tells me "Weight must be numeric"

                    What am I doing wrong?

                    Comment

                    • rents
                      New Member
                      • Mar 2007
                      • 26

                      #11
                      Ok. It seems like everything is running ok. I'm still having trouble with the "numeric" problem as stated in the last post.

                      The final thing I need to do is this:

                      Input validation: Do not accept values of 0 or less for the weight of the package. Do not accept weights of more thann 20 kg(this is the maximum weight the company will ship) Do not accept distances of less than 10 miles or more than 3000 miles. These are the company's minimum and maximum shipping distances. Use exception handling to check for non-numeric data.

                      Where would I put this in the code window? and like how would I type it in?

                      Comment

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

                        #12
                        Originally posted by rents
                        Private Sub Total_Click() 'total button calculator

                        Dim num_one As Currency 'see textbox named Price.Text
                        Dim num_two As Integer 'see textbox named Price.Text
                        Dim Total_results_n um As Currency

                        ok..for this part..where it says Dim num_one As Currency..

                        what should I put in for mine..for my weight textbox (txtweight)

                        Dim decWeight As ???? (it's supposed to run in kg)
                        Code:
                        Dim decWeight As Integer     'you are adding numerics here

                        Comment

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

                          #13
                          Originally posted by rents
                          ok, I've kind of figured out what I am doing. But now I've run into a problem.
                          I have these IF statements in my calculate button

                          Code:
                                  If IsNumeric(txtWeight.Text) = False Then
                                      lblErrorMessage.Text = "Weight must numeric"
                                      lblErrorMessage.Visible = True
                                      Return
                                  End If
                          
                                  If IsNumeric(txtDistance.Text) = False Then
                                      lblErrorMessage.Text = "Distance must be numeric"
                                      lblErrorMessage.Visible = True
                                      Return
                                  End If
                          but when I test the Distance with some letter, the error label tells me "Weight must be numeric"

                          What am I doing wrong?
                          You are doing fine. You have it set to find numerics, so it's a good catch that your message tells you the program needs numerics. Please continue, Great Job! Add a number in there, you will find you do not get the message therefore :-)

                          Comment

                          • rents
                            New Member
                            • Mar 2007
                            • 26

                            #14
                            Dokoll
                            Thanks so much for your help!
                            I'm still working on this last part, so if you could help me out with this one, that would be it :)



                            Input validation: Do not accept values of 0 or less for the weight of the package. Do not accept weights of more thann 20 kg(this is the maximum weight the company will ship) Do not accept distances of less than 10 miles or more than 3000 miles. These are the company's minimum and maximum shipping distances. Use exception handling to check for non-numeric data.

                            Where would I put this in the code window? and like how would I type it in?

                            Comment

                            • rents
                              New Member
                              • Mar 2007
                              • 26

                              #15
                              '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?

                              Comment

                              Working...