The following is the code from an assignment I am struggling with. I am supposed to change the GetGallons function procedure to a sub procedure in a class that i created in another project.. Here is the code from the original class:
Public Class RectangularPool
Private _decLength As Decimal
Private _decWidth As Decimal
Private _decDepth As Decimal
Public Property Length As Decimal
Get
Return _decLength
End Get
Set(ByVal value As Decimal)
If value > 0 Then
_decLength = value
Else
_decLength = 0
End If
End Set
End Property
Public Property Width As Decimal
Get
Return _decWidth
End Get
Set(ByVal value As Decimal)
If value > 0 Then
_decWidth = value
Else
_decWidth = 0
End If
End Set
End Property
Public Property Depth As Decimal
Get
Return _decDepth
End Get
Set(ByVal value As Decimal)
If value > 0 Then
_decDepth = value
Else
_decDepth = 0
End If
End Set
End Property
Public Sub New()
'default constructor
_decLength = 0
_decWidth = 0
_decDepth = 0
End Sub
Public Function GetVolume() As Decimal
Return _decLength * _decWidth * _decDepth
End Function
Public Function GetGallons() As Decimal
Dim decVol As Decimal
decVol = GetVolume()
Return decVol * 7.48
End Function
End Class
Here is the code from the main form:
Public Class frmMain
Private Sub btnCalc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalc.Click
' displays the number of gallons
Dim pool As New RectangularPool
Dim decGallons As Decimal
Decimal.TryParse(txtLength.Text, pool.Length)
Decimal.TryParse(txtWidth.Text, pool.Width)
Decimal.TryParse(txtDepth.Text, pool.Depth)
decGallons = pool.GetGallons
lblGallons.Text = decGallons.ToString("N0")
txtLength.Focus()
End Sub
Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub txtDepth_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtDepth.KeyPress
' allows only numbers, the period, and the Backspace key
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso
e.KeyChar <> "." AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub txtDepth_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtDepth.TextChanged
lblGallons.Text = String.Empty
End Sub
Private Sub txtLength_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtLength.KeyPress
' allows only numbers, the period, and the Backspace key
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso
e.KeyChar <> "." AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub txtLength_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtLength.TextChanged
lblGallons.Text = String.Empty
End Sub
Private Sub txtWidth_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtWidth.KeyPress
' allows only numbers, the period, and the Backspace key
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso
e.KeyChar <> "." AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub txtWidth_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtWidth.TextChanged
lblGallons.Text = String.Empty
End Sub
Private Sub lblGallons_Click(sender As System.Object, e As System.EventArgs) Handles lblGallons.Click
End Sub
End Class
...I am supposed to change the GetGallons function procedure to a sub procedure and then modify the btnCal controls click event to accomodate the modification to the GetGallons procedure. I could really used an experienced hand here. Thank you.