Visual Basic

posted by .

Alright, so I'm trying to code a program to where I can plug in two numbers and get a commission cost out of them.

I'm having a hard time setting up the code, and I'm really looking for some guidance. I have this as the code so far:

Public Class Form1
'Declare module-lvel variables and constants
Private SellingPriceInteger, CostValueInteger As Integer
Const COMMISSION_RATE_Decimal As Decimal = 0.2D
Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click
'Prints the Form.
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
End Sub
Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
'Calculates the Comission
Dim SalesPriceInteger As Integer, CostValueInteger As Integer
Dim COMMISSION_RATE_Decimal As Decimal = 0.2D

'Convert quantity to numeric variable.
SalesPriceInteger = Integer.Parse(SPTextBox.Text)
Catch ex As Exception

End Try

'Convert price if quantity was successful.

Catch ex As Exception

End Try
End Sub
End Class

Basically, I'm in need of some guidance when it comes to Try/Catch, along with figuring out if what I'm typing would work, or if I'm missing a code that defines Integer.

  • Visual Basic -

    The logic looks OK, but incomplete.

    It is good practice to use try/catch blocks for user entered values. You need to elaborate on that, i.e. error messages, try again, etc.

    There is one little point you can improve on: you have defined the commission rate in two separate places. In normal programming, this is not a good idea. If tomorrow the rate changes, you will need to change it in two different places. What if your assistant programmer forgot or did not know that it is defined in two places?

    So try to define "global" constants in one place, and make it accessible to everyone.

    I also have a question: what is the commission structure? Most of the time, the commission depends only on the selling price. Here you enter the cost AND the selling price. Is the cost used at all?

  • Visual Basic -

    First off, Thank you MathMate.

    As for it being incomplete, I'm in the process of writing it, I've just run into a wall, really.

    The commission structure is Commission = Commission rate * (Sales price - Cost Value)

    I was told by the professor to use one of the hands-on exercises as a loose guideline, and I'm not one for thinking too freely when it comes to code, so I ended up copying quite a bit of it over, tweaking it for the names of my TextBoxes. I've been trying to find a guideline for this specific problem, but have had no luck.

    This is an online class, and I'm really not learning much from just reading the book, so any advice would be helpful.

  • Visual Basic -

    Just like we cannot learn to drive a car if we don't have one, do you happen to have VB installed on your computer?

    One of the few advantages of a learner-programmer is you have unlimited number of tries, and eventually you'll get somewhere. Evidently you cannot try blindly, but much of the learning is trying things out. You try, the VB compiler catches!

    If you have your hands on the VB compiler, you will find that much of the mundane stuff is automated, like the routines for the text-boxes, etc. You only have to fill in the "meat", which is what you're after.

    In any case, I suppose you will need two textboxes to enter the selling price and the cost, a button to calculate, and a textbox to display the results. All this can be done by drag-and-drop on the GUI (graphics user interface) of VB. You only have to tweak the error detecting procedures.

    Your first priority is to make something that compiles, as simple as you wish, even if it does nothing.
    Then you can test your own code, incrementally, so that if there is an error, you know exactly where it happens.

    If it does not compile, and you have difficulty finding the problem, post.

  • Visual Basic -

    How to create an application that allows the user to enter the amount of a purchase. the program should then calculate the state and country sales tax. assume the state sales tax is 4 percent and the country sales tax is 2 percent. the program should display the amount of the purchase, the state sales tax, the country sales tax, the total sales tax, and the total of the sale (which is the sum of the amount of purchase plus the total sales tax).

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions


    PLS, I NEED TO BE GUIDED ON HOW TO WRITE A SIMPLE PROGRAM IN BASIC THAT WOULD PROMPT 3 LEVELS OF AUTHENTICATION WHEN UNAUTHORISED LOG-ON IS EFFECTED. You are not going to be able here to get detailed help on the program code, as there …
  2. algebra

    if there is a 4 digit code and the number choices are 0-9 and the last two numbers in the code are 0 and 7 what are all the code possibilites?
  3. Programming

    Here is the question that I need help to write the code for the following program in Visual Basic 2010. I am trying to write the code but it has a run time error. If your could helps me to write the code it would be greatly appreciated. …
  4. Ms Visio

    • 2. Construct a data dictionary and draw a hierarchy chart and flowchart or pseudocode for a program to calculate commissions. Output. Output is the commission report shown in the spacing chart that follows. At most, 50 detail lines …
  5. Programming

    Read two numbers from the keyboard Display the menu options as follows: 1 - computes the sum of two numbers. 2 - computes the difference (first minus second). 3 - computes the product of the two numbers. 4 - if the second number is …
  6. Programming (Visual Basic)

    Im seem to be having trouble with this Exercise. Would you mind helping me please?
  7. History

    The Code Talkers were members of which Native American tribe?
  8. C++

    I am trying to create a program that displays shipping charges for two region codes. The region code has to have exactly 3 characters (the letter A or B followed by two numbers). Display a message if invalid region code is entered. …
  9. science

    Write a java program using classes and object to read the em[loyee code (Integer), Imployee name (string), Basic salary )double), Category (Character)then calculate the bonus(double)and the total salary(double)eligible for each employ. …
  10. computer,science, java

    Inorder to motivate the employees, the company has decided to announce the different types of bonus depends up on the employee’s Grade. If the employee belong to Grade A bonus=20% basic Grade B bonus=15% basic Grade C bonus=10% basic …

More Similar Questions