Question
I am trying to get my Text at the bottom to show the calculations correctly. I am working with sub classes and I am sure
I am trying to get my Text at the bottom to show the calculations correctly. I am working with sub classes and I am sure something in my code is incorrect. Below is my code from my main form and my 2 sub forms.
Option Strict On
Public Class frmRealEstate Private Sub lblTitle_Click(sender As Object, e As EventArgs) Handles lblTitle.Click
End Sub
Private Sub frmRealEstate_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click ' This button calculates the return investment of a property based on an investment location over the given number of years ' and the home price.
Dim objInvestment As Investment Dim InputError As Boolean = False
' Is name entered properly If txtName.TextLength
Private Sub txtYears_TextChanged(sender As Object, e As EventArgs) Handles txtYears.TextChanged
End Sub
Private Sub cboCity_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboCity.SelectedIndexChanged
End Sub
Private Sub txtPrice_TextChanged(sender As Object, e As EventArgs) Handles txtPrice.TextChanged
End Sub
Private Sub txtName_TextChanged(sender As Object, e As EventArgs) Handles txtName.TextChanged
End Sub
Private Sub lblName_Click(sender As Object, e As EventArgs) Handles lblName.Click
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click ' This event handler is executed when user taps or clicks the Clear Form button. It resets all objects on the user interface.
txtName.Clear() txtYears.Clear() cboCity.SelectedIndex = -1 txtPrice.Clear() txtName.Focus()
End Sub
Private Sub lblInvestmentReturns_Click(sender As Object, e As EventArgs) Handles lblInvestmentReturns.Click
End Sub End Class
Public Class Investment
' Class variables Protected _strName As String Protected _intYears As Integer Protected _strCity As String Protected _intPrice As Integer Protected _decInvestment As Decimal Protected _Memphis As Boolean Protected _Ocala As Boolean Protected _Atlanta As Boolean Protected _Phoenix As Boolean Protected _Ogden As Boolean
Dim objInvestmentfile As InvestmentFile Private text1 As String Private text2 As String Private v As String Private text3 As String
Sub New(ByVal strName As String, ByVal intYears As String, ByVal strCity As String, ByVal intPrice As String, ByVal Memphis As Boolean, ByVal Ocala As Boolean, ByVal Atlanta As Boolean, ByVal Phoenix As Boolean, ByVal Ogden As Boolean) ' This subprocedure is a constructor for the Investment class. It is called when the object is instantisted with arguments
' The following code assigns the arguments to class variables
_strName = strName _intYears = Convert.ToInt32(intYears) _strCity = strCity _intPrice = Convert.ToInt32(intPrice) _Memphis = Memphis _Ocala = Ocala _Atlanta = Atlanta _Phoenix = Phoenix _Ogden = Ogden
End Sub
Public Sub New(text1 As String, text2 As String, v As String, text3 As String) Me.text1 = text1 Me.text2 = text2 Me.v = v Me.text3 = text3 End Sub
Overridable Function ComputeCosts() As Decimal ' This function computes the investments, writes a record in the investment file and returns the investment figure
' Define variables Dim CityPercent As Decimal Const cdecMemphis As Decimal = 0.1038D Const cdecOcala As Decimal = 0.1023D
'calculate investment If _Memphis Then CityPercent = cdecMemphis ElseIf _Ocala Then CityPercent = cdecOcala End If _decInvestment = (_intYears * CityPercent) * _intPrice
'Write the investment record objInvestmentfile = New InvestmentFile(_strName, _strCity, _decInvestment) objInvestmentfile.WriteRecord()
'Return the calculated investment
Return _decInvestment
End Function
End Class
Public Class InvestmentFile Inherits Investment
' Class Variables Private _strName As String Private _intYears As Integer Private _strCity As String Private _intPrice As Integer Private _decInvestment As Decimal Private _Memphis As String Private _Ocala As String Private _Atlanta As String Private _Phoenix As String Private _Ogden As String
Dim objInvestmentfile As InvestmentFile Sub New(ByVal strName As String, ByVal intYears As String, ByVal strCity As String, ByVal intPrice As String, ByVal Memphis As Boolean, ByVal Ocala As Boolean, ByVal Atlanta As Boolean, ByVal Phoenix As Boolean, ByVal Ogden As Boolean)
MyBase.New(strName, intYears, strCity, intPrice, Memphis, Ocala, Atlanta, Phoenix, Ogden)
_strName = strName _intYears = Convert.ToInt32(intYears) _strCity = strCity _intPrice = Convert.ToInt32(intPrice) _Memphis = CType(Memphis, String) _Ocala = CType(Ocala, String) _Atlanta = CType(Atlanta, String) _Phoenix = CType(Phoenix, String) _Ogden = CType(Ogden, String)
End Sub
Public Sub New(_strName As String, _strCity As String, _decInvestment As Decimal) Me._strName = _strName Me._strCity = _strCity Me._decInvestment = _decInvestment End Sub
Sub WriteRecord() ' This subprocedure opens the investments output file and then writes a record in the comma-delimited file
Dim strNameandLocationOfFile As String = "C:\Users\MillerRD\Documents\VB class\week 5\VB Auto 11 Real Estate\VB Auto 11 Real Estate\Investsments.txt"
Try Dim objWriter As IO.StreamWriter = IO.File.AppendText(strNameandLocationOfFile)
objWriter.Write(_strName & ",") objWriter.Close()
Catch ex As Exception MsgBox("No device available - program aborted", , "Error")
End Try
End Sub Overrides Function ComputeCosts() As Decimal
' Define variables Dim CityPercent As Decimal Const cdecMemphis As Decimal = 0.1038D Const cdecOcala As Decimal = 0.1023D
'calculate investment If CBool(_Memphis) Then CityPercent = cdecMemphis ElseIf CBool(_Ocala) Then CityPercent = cdecOcala End If _decInvestment = (_intYears * CityPercent) * _intPrice _decInvestment = _intYears 'Write the investment record 'objInvestmentfile = New InvestmentFile(_strName, _strCity) objInvestmentfile.WriteRecord()
'Return the calculated investment
Return _decInvestment End Function End Class
USE CASE DEFINITION 1. The user views the opening screen 2. The buyer enters his name, the number of rental years, and rental home price 3. The user selects an option from the list of cities 4. T 5. The program displays the return on investment amount 6. The program writes a record of the investment in a text file 7. A Clear Form button is available to clear the form he user taps or clicks the Return on Investment button FIGURE 11-59 Real Estate Investment Invest in Rental Real Estate retum on Name: Lacas Paaley advce Rental Years 5 Select City: Ocala FL 10.23% Home Price: Return on Investment Clear Form Investment Return: $51,150.00 USE CASE DEFINITION 1. The user views the opening screen 2. The buyer enters his name, the number of rental years, and rental home price 3. The user selects an option from the list of cities 4. T 5. The program displays the return on investment amount 6. The program writes a record of the investment in a text file 7. A Clear Form button is available to clear the form he user taps or clicks the Return on Investment button FIGURE 11-59 Real Estate Investment Invest in Rental Real Estate retum on Name: Lacas Paaley advce Rental Years 5 Select City: Ocala FL 10.23% Home Price: Return on Investment Clear Form Investment Return: $51,150.00
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started