why will this program not build or run?

  • Thread starter Thread starter Ron
  • Start date Start date
R

Ron

I've got this simple program that will not build or run, any idea
what I am doing wrong?

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnCalculate.Click
Dim c As Double = CDbl(txtOrderCost.Text)
Dim r As Integer = CInt(txtMonthlyDemand.Text)
Dim p As Double = CDbl(txtPartCost.Text)
Dim f As Double = 0.15
Dim h As Double = p * f
Dim eoq As Double = 0

eoq = (p / r) * 0.15 * 332100

lblEOQ.Text = "EOQ = " & eoq

End Sub
 
A double is expection whole numbers & not 0.15

try using 'Decimal' as the result instead of 'Double'

Example:

Dim eoq As Decimal = (p / r) * 0.15 * 332100
lblEOQ.Text = "EOQ = " & eoq

I haven't tried your code because you never gave any possible values for
OrderCost, MonthlyDemand or PartCost
 
Well, if it won't compile (build) then it certainly won't run so the fact
that it won't run is irrevalent.

What compile-time error(s) are you getting?
 
OK here is what I have for the code now and it still will not load my
form when I run it.

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnCalculate.Click
Dim c As Double = CDbl(txtOrderCost.Text)
Dim r As Integer = CInt(txtMonthlyDemand.Text)
Dim p As Double = CDbl(txtPartCost.Text)
Dim f As Decimal = CDec(0.15)
Dim h As Double = p * f
Dim eoq As Decimal = CDec((p / r) * 0.15 * 332100)

'for the eoq, use the below formula as a guide
'replace with correct formula
'eoq = CDec((p / r) * 0.15 * 332100)

lblEOQ.Text = "EOQ = " & eoq

End Sub
FOR THE INPUTS I AM USING :
order cost 25.00
Monthly demand 90000
Part cost 18.75
Thats what I want to use but the form never opens for me to enter them
in, I dont even get that far.
 
OK here is what I have for the code now and it still will not load my
form when I run it.

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnCalculate.Click
Dim c As Double = CDbl(txtOrderCost.Text)
Dim r As Integer = CInt(txtMonthlyDemand.Text)
Dim p As Double = CDbl(txtPartCost.Text)
Dim f As Decimal = CDec(0.15)
Dim h As Double = p * f
Dim eoq As Decimal = CDec((p / r) * 0.15 * 332100)

'for the eoq, use the below formula as a guide
'replace with correct formula
'eoq = CDec((p / r) * 0.15 * 332100)

lblEOQ.Text = "EOQ = " & eoq

End Sub
FOR THE INPUTS I AM USING :
order cost 25.00
Monthly demand 90000
Part cost 18.75
Thats what I want to use but the form never opens for me to enter them
in, I dont even get that far.
The only error I get says the program has exited with e 0 (0x0)
 
Hmmm. I just created a new project in VB 2005 and craeted the 3 text boxes
that you listed, the one label, and the calculate button. I did not have
any problems at all running the program. It would take all but 3 minutes,
have you tried creating a completely new project and trying this again?

Tony
 
Describing what happens in the first place is always a good idea ;-)

For now it would make me thought that you just show the form. But showing
the form doesn't mean that control is necessarily transfered to the form. In
this case the program just continues and ends...

What is your startup object ? IMO the relevant code is the code that launch
the forms...
 
Ron

I have used the values you have given me & I get the result of: 'EOQ =
103.78125'

Here is the code:

Dim c As Double = 25.00
Dim r As Integer = 9000
Dim p As Double = 18.75
Dim f As Double = 0.15
Dim h As Double = p * f
Dim eoq As Double = CDbl((p / r) * 0.15 * 332100)
TextBox1.Text = "EOQ = " & eoq

The code compiles for me ok with no errors

Maybe you don't need 5 decimal places then it could be formatted simply by:

TextBox1.Text = "EOQ = " & Format(eoq, "#.###")
Result: 'EOQ = 103.781'

This will give you the whole number & then to 3 decimal places:

TextBox1.Text = "EOQ = " & Format(eoq, "#.##")
Result: 'EOQ = 103.78'

The above to 2 decimal places & so on

I hope this helps,
 
dotnet is too verbose; your IDE is expecting more verbosity

I would reccomend just adding a whole assload of more code in it and
see if it works then
 
Back
Top