Help with program...

titanwrex

New member
Joined
Apr 6, 2012
Messages
2
Programming Experience
Beginner
Hey guys i have to write a program for class here is the criteria:

You are to create an application that will figure the amount of commission that a stock broker will receive based on the amount of the sale. The user should be able to enter a stock transaction and determine the stock holders commission. Each transaction includes the following data:

  1. Stock name
  2. Price per share
  3. Number of shares involved
  4. Stock holders name
Assume price per share = P. The stock brokers commission is computed in the following manner: If the P (price per share) is less than or equal to $50.00, the commission rate is $0.19 per share; if P is greater than $50.00, the commission rate is $0.26 per share. If the number of shares sold is less than 150, the commission is 1.5 times the rate per share. Display the results, and all transaction information on a separate form. Validate all data entries and make the forms as user friendly as possible. Complete the Phases listed below to solve this problem.

For now i just wanted it see if the total stock is correct so i put the commission in a total text box:
when i try running it, it gives me this error saying something about dependencies...
I dont know what's wrong
Can you help me fix it? i am a beginner
Heres my code so far:

Option Strict On

Public Class Form1

Dim dblPrice, dblNumber, dblCommissionRate, dblCommission As Double
Dim strStockName, strStockbroker As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

txtPrice.Text = CStr(dblPrice)
txtNumber.Text = CStr(dblNumber)


If dblPrice <= 50.0 Then
dblCommissionRate = 0.19
Else
If dblPrice > 50.0 Then
dblCommissionRate = 0.26
End If
End If

If dblNumber <= 150.0 Then
dblCommission = 1.5 * dblCommissionRate
Else
If dblNumber > 150 Then
dblCommission = 1.0 * dblCommissionRate
End If
End If
txttotal.Text = CStr(dblCommission * dblNumber)

End Sub
End Class
 
Heres my code so far:

Option Strict On

Public Class Form1

Dim dblPrice, dblNumber, dblCommissionRate, dblCommission As Double
Dim strStockName, strStockbroker As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

txtPrice.Text = CStr(dblPrice)
txtNumber.Text = CStr(dblNumber)


If dblPrice <= 50.0 Then
dblCommissionRate = 0.19
Else
If dblPrice > 50.0 Then
dblCommissionRate = 0.26
End If
End If

If dblNumber <= 150.0 Then
dblCommission = 1.5 * dblCommissionRate
Else
If dblNumber > 150 Then
dblCommission = 1.0 * dblCommissionRate
End If
End If
txttotal.Text = CStr(dblCommission * dblNumber)

End Sub
End Class

The code here is not going to do anything, dblPrice and dblNumber are not set to anything so when run will have a value of 0. So no matter what you enter into the textboxes you will have 0,0,0. I put the program together to try out the theory and surprise, surprise it was 0,0,0.

Not sure why you are getting an error, unless you have code elsewhere. When I ran the program I did not get an error.

Try:

'This sets the two variables Price and Number to what you have entered in the two text boxes giving the rest of the code something to calculate.

dblPrice = CDbl(txtPrice.Text)
dblNumber = CDbl(txtNumber.Text)

instead of

'All the below code will do is put 0's into the two textboxes so when it runs the rest of the code it will calculate out to 0.

txtPrice.Text = CStr(dblPrice)
txtNumber.Text = CStr(dblNumber)

As far as I can see this makes more sense for the button code and will give you the results you require.

Regards :cocksure:
 
Thanks! I put it in yet for some reason it gives me this error:

Untitled.png

3+MJODy2VmWUwAAAABJRU5ErkJggg==
 
Thanks! I put it in yet for some reason it gives me this error:

View attachment 3266

3+MJODy2VmWUwAAAABJRU5ErkJggg==
That simply means you removed/deleted a required dependency (probably a dll) which has nothing to do with adding the
dblPrice = CDbl(txtPrice.Text)
dblNumber = CDbl(txtNumber.Text)
lines.

And really you should be using Double.TryParse() when parsing input, especially from the user.
 
Thanks for that JuggaloBrotha I did not know about the Double.TryParse this is something to remember for me in the future.

Definately something missing in your code as the code shown works on it's own so you must have other code that has need of the missing dependency (Dll)
I would go through your code and check for the omission.

Good Luck
 
Back
Top