Click here to Skip to main content
15,899,124 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
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:

VB
'Form Portion of the program
Public Class frmMobilePhoneReg
    

   
    Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
        Dim objBuyer As Buyer
        ' Dim objDataPlan As DataPlan
        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


'Buyer Clsss
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

'Buyer cost 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)
        ' TODO: Complete member initialization 
        _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

'Data Plan 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
    ' Overrides Function ComputeCosts() As Decimal
    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
Posted
Updated 13-Apr-16 12:31pm
v4
Comments
an0ther1 7-Apr-16 20:47pm    
So where is your error?
Run the program in a debugger and step through it to see what values you are getting & are they what the code expects.
Sergey Alexandrovich Kryukov 7-Apr-16 22:11pm    
Visual Studio is not "dealing with classes" you write (unless you write a VS add-on) — this is nothing but IDE.
So far, your post does not make sense; this is a mere code dump (not formatted). You did not ask any questions.
—SA
ProgrammerA 8-Apr-16 8:44am    
http://imgur.com/ZbxYdLc here is the link form and errors at the bottom.
Richard MacCutchan 8-Apr-16 9:01am    
Although the image is very small the messages are quite clear. You need to fix those errors first.

1 solution

In Visual Studio, double click on error number 1.

The IDE will take you to the part of the code that is in error, in this case
objBuyerCostsFile = New BuyerCost(_strBLName, _strBAddress, _strBZipCode, _strBEmail)
You only have one constructor for class BuyerCost:
VB.NET
Sub New(strBLName As String, strBAddress As String, strBZipCode As String, strBEmail As String, decBPlanCost As String)
So you either need to correct the first line by putting in a value for the decBPlanCost parameter OR create another constructor where that value is not required OR provide an optional value for that parameter.

You have another problem with that constructor in that you have declared the parameter as String but I suspect you actually meant Decimal

If you double-click on the 2nd error then you will be taken to your DataPlan class and the method ComputeCosts. For whatever reason you have commented out the correct definition with Overrides keyword.

If you hit any more compile errors or warnings then follow the same technique - double-click the error to locate the problem and fix it. Always start with Error number 1 as many subsequent errors will disappear as you fix earlier ones
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900