I have some code that is deliberately programmed in a non-standard way, so I'm not looking for someone to point that out. When it's coded right, I get the proper results. However the results are not what I thought they would be with the non-standard code.
I spent some time walking through the code with the debugger. Everything was working right until just before the end, when the correct value that should have been returned changed to minus 1. Purely as a matter of curiosity, I'd like to know what's going on with the code to produce the strange result. Here it is:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cls As New Class1
cls.Area = 8.34D
cls.Price = 31.22D
MsgBox(Format(cls.TotalCost, "Fixed"))
End Sub
End Class
Public Class Class1
Private pricee As Decimal
Private areea As Decimal
Private totCost As Decimal
Public ReadOnly Property TotalCost() As Decimal
Get
Return totCost = Area * Price
End Get
End Property
Public Property Area() As Decimal
Get
Return areea
End Get
Set(ByVal value As Decimal)
If value < 1000 Then
areea = value
Else
areea = 0
End If
totCost = value * Price
End Set
End Property
Public Property Price() As Decimal
Get
Return pricee
End Get
Set(ByVal value As Decimal)
pricee = value
totCost = value * Area
End Set
End Property
End Class