The issue is I am not getting output and the correct setup of the classes to program. If you need the form as well, please let me know. This program is to calculate the costs of data plans for mobile phones. Visual Studio 2012 is what I am using.
Here is the form with the two issues. I am trying to return the final cost to the form itself from the screen shot
What I have tried:
Public Class frmMobilePhoneReg
Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
Dim objBuyer As Buyer
Dim InputError As Boolean = False
If txtLName.TextLength < 1 Or txtLName.Text < "A" Then
MsgBox("Enter your Last Name in the Last Name box", , "Error")
txtLName.Clear()
txtLName.Focus()
InputError = True
ElseIf txtStreetAddr.Text = "" Then
MsgBox("Enter your Street Address box", , "Error")
txtStreetAddr.Clear()
txtStreetAddr.Focus()
InputError = True
ElseIf txtZipCode.TextLength < 1 Or txtZipCode.TextLength > 5 Then
MsgBox("Enter your Zip Code in the box", , "Error")
txtZipCode.Clear()
txtZipCode.Focus()
InputError = True
ElseIf cboPlanChoice.SelectedIndex < 0 Then
MsgBox("Please select a plan", , "Error")
cboPlanChoice.Focus()
InputError = True
ElseIf cboHotSpot.SelectedIndex < 0 Then
MsgBox("Please select a hotspot", , "Error")
cboHotSpot.Focus()
InputError = True
End If
If Not InputError Then
If rdoInternet.Checked Then
lblEmailAddr.Visible = True
txtEmailAddr.Visible = True
If txtLName.TextLength < 1 Or txtLName.Text < "A" Then
MsgBox("Enter your email in the box", , "Error")
txtEmailAddr.Clear()
txtEmailAddr.Focus()
InputError = True
End If
ElseIf rdoInStore.Checked Then
txtEmailAddr.Text = ""
End If
End If
objBuyer = New Buyer(txtLName.Text, txtStreetAddr.Text, txtZipCode.Text, txtEmailAddr.Text, cboPlanChoice.SelectedItem, cboHotSpot.SelectedItem)
lblCustCost.Visible = True
lblCustCost.Text = "Total costs are: " & objBuyer.ComputeCosts()
End Sub
Private Sub cboPlanChoice_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboPlanChoice.SelectedIndexChanged
End Sub
Private Sub cboHotSpot_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboHotSpot.SelectedIndexChanged
End Sub
Private Sub rdoInStore_CheckedChanged(sender As Object, e As EventArgs) Handles rdoInStore.CheckedChanged
End Sub
Private Sub rdoInternet_CheckedChanged(sender As Object, e As EventArgs) Handles rdoInternet.CheckedChanged
End Sub
Private Sub frmMobilePhoneReg_Load(sender As Object, e As EventArgs) Handles MyBase.Load
cboPlanChoice.SelectedIndex = 0
cboHotSpot.SelectedIndex = 0
txtLName.Focus()
End Sub
End Class
Option Strict On
Public Class Buyer
Protected _strBLName As String
Protected _strBAddress As String
Protected _strBZipCode As String
Protected _strBEmail As String
Protected _strBPlCho As String
Protected _strHotSpot As String
Dim objBuyerCostsFile As BuyerCost
Dim decCost As Decimal
Sub New(ByVal strBLName As String, ByVal strBAddress As String, ByVal strBZipCode As String, ByVal strBEmail As String, _
ByVal strBPlCho As String, ByVal strHotSpot As String)
_strBLName = strBLName
_strBAddress = strBAddress
_strBZipCode = strBZipCode
_strBEmail = strBEmail
_strBPlCho = strBPlCho
_strHotSpot = strHotSpot
End Sub
Overridable Function ComputeCosts() As Decimal
objBuyerCostsFile = New BuyerCost(_strBLName, _strBAddress, _strBZipCode, _strBEmail)
objBuyerCostsFile.WriteRecord()
Return decCost
End Function
End Class
Public Class BuyerCost
Private _strBLName As String
Private _strBAddress As String
Private _strBZipCode As String
Private _strBType As String
Private _strDPChoice As String
Private _strDPHotspot As String
Private _decBPlanCost As Decimal
Private _strBEmail As String
Sub New(strBLName As String, strBAddress As String, strBZipCode As String, strBEmail As String, decBPlanCost As String)
_strBLName = strBLName
_strBAddress = strBAddress
_strBZipCode = strBZipCode
_strBEmail = strBEmail
_decBPlanCost = decBPlanCost
End Sub
Sub WriteRecord()
Dim strNameandLocationOfFile As String = "e:\StudentCosts.txt"
Try
Dim objWriter As IO.StreamWriter = _
IO.File.AppendText(strNameandLocationOfFile)
objWriter.Write(_strBLName & ",")
objWriter.Write(_strBZipCode & ",")
objWriter.Write(_strDPChoice & ",")
objWriter.Write(_decBPlanCost)
objWriter.Close()
Catch ex As Exception
MsgBox("No device available - program aborted", , "Error")
Application.Exit()
End Try
End Sub
End Class
Option Strict On
Public Class DataPlan
Inherits Buyer
Private _InStore As Boolean
Private _Internet As Boolean
Private _DataP1GB As Boolean
Private _DataP2GB As Boolean
Private _DataP4GB As Boolean
Private _DataPUnl As Boolean
Private _AddYHotSpot As Boolean
Private _AddNHotSpot As Boolean
Dim objBuyerCostsFile As BuyerCost
Sub New(ByVal BLName As String, ByVal BAddress As String, _
ByVal BZipCode As String, ByVal BEmail As String, _
ByVal DPChoice As String, ByVal DPHotspot As String, _
ByVal DataP1GB As Boolean, ByVal DataP2GB As Boolean, _
ByVal DataP4GB As Boolean, ByVal DataPUnl As Boolean, _
ByVal AddYHotSpot As Boolean, ByVal AddNHotSpot As Boolean)
MyBase.New(BLName, BAddress, BZipCode, BEmail, DPChoice, DPHotspot)
_DataP1GB = DataP1GB
_DataP2GB = DataP2GB
_DataP4GB = DataP4GB
_DataPUnl = DataPUnl
_AddYHotSpot = AddYHotSpot
_AddNHotSpot = AddNHotSpot
End Sub
Function ComputeCosts() As Decimal
Dim BuyerTypeSCost As Decimal
Dim BuyerDataPCost As Decimal
Dim BuyerAddHSCost As Decimal
Dim BuyerTotalCost As Decimal
Const cdecInStoreSCost As Decimal = 0D
Const cdecInternetSCost As Decimal = 28D
Const cdecDataP1GBCost As Decimal = 30D
Const cdecDataP2GBCost As Decimal = 50D
Const cdecDataP4GBCost As Decimal = 70D
Const cdecDataPUnlCost As Decimal = 120D
Const cdecAddYHotSpCost As Decimal = 20D
Const cdecAddNHotSpCost As Decimal = 0D
Const cdecInStoreTaxCost As Decimal = 0.0775D
If _DataP1GB Then
BuyerDataPCost = cdecDataP1GBCost
ElseIf _DataP2GB Then
BuyerDataPCost = cdecDataP2GBCost
ElseIf _DataP4GB Then
BuyerDataPCost = cdecDataP4GBCost
ElseIf _DataPUnl Then
BuyerDataPCost = cdecDataPUnlCost
End If
If _AddYHotSpot Then
BuyerAddHSCost = cdecAddYHotSpCost
ElseIf _AddYHotSpot Then
BuyerAddHSCost = cdecAddNHotSpCost
End If
If _Internet Then
BuyerTypeSCost = cdecInternetSCost
BuyerTotalCost = BuyerDataPCost + BuyerAddHSCost + BuyerTypeSCost
ElseIf _InStore Then
BuyerTypeSCost = cdecInStoreSCost
BuyerTotalCost = (BuyerDataPCost + BuyerAddHSCost) * cdecInStoreTaxCost
End If
Return BuyerTotalCost
End Function
End Class