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
PrintForm1.Print()
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

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

End Try

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.

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?

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.

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.

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).

It looks like you're working on a program to calculate commission costs based on two input numbers. I can help guide you through the process and address your concerns.

First, I see that you have declared some module-level variables and constants at the beginning of your code. This is a good practice, as it allows you to use these variables throughout your code without needing to redeclare them every time.

To clarify, in your code, you declared the variables "SellingPriceInteger" and "CostValueInteger" as Integer. These variables are used to store the selling price and cost value respectively. The constant "COMMISSION_RATE_Decimal" is declared as Decimal and represents the commission rate.

Moving on, you have implemented two event handlers: one for the "PrintButton" click and another for the "CalculateButton" click. Let's focus on the "CalculateButton" click event handler.

Inside the "CalculateButton_Click" event handler, you have declared some local variables: "SalesPriceInteger" and "CostValueInteger". These variables will be used to store the parsed integer values from the corresponding text boxes.

Now, let's address your concerns with the Try/Catch blocks. The purpose of a Try/Catch block is to handle exceptions that might occur during the execution of your code. It helps you handle situations where there could be errors in the input or other unexpected issues.

In your code, you have already implemented the Try block to parse the value from the "SPTextBox" (presumably the text box for the selling price). However, you currently don't have any code inside the Try block to handle the parsed value or any potential exception.

To fix this, you can add code inside the Try block to handle the parsed value or any exception that might occur. For example, you can assign the parsed value to the "SalesPriceInteger" variable or display an error message if parsing fails.

Here's an example of how you can update your code:

```vb
Try
'Convert quantity to numeric variable.
SalesPriceInteger = Integer.Parse(SPTextBox.Text)

' Use the parsed value here or perform any other necessary calculations
' For example:
' Commission = SalesPriceInteger * COMMISSION_RATE_Decimal
' Display the Commission value in a textbox or label

Catch ex As Exception
' Handle the exception here
' For example, display an error message
MessageBox.Show("Invalid input for selling price.")
End Try
```

Similarly, you can add a Try/Catch block for the cost value if you need to parse it as well.

Finally, regarding your concern about missing a code that defines Integer, from the provided code snippet, you have already declared the necessary variables as Integer at the module level ("SellingPriceInteger", "CostValueInteger") and inside the event handler ("SalesPriceInteger", "CostValueInteger").

As long as you have imported the necessary namespaces at the top of your code file (e.g., `Imports System`), you should have access to the Integer data type.

I hope this guidance helps you progress with your program.