Hi everyone!

At the moment I am working on an OOP bank account program as an assignment in VB.Net.

FYI:It has a credit account class with properties of AccountName, AccountNumber and Balance. The credit account class has two methods - deposit and withdraw. You can overdraw on the credit account, but not on the savings account. If the user tries to overdraw on the savings account, a user defined event displays an error message.

I think:-/ I've written the Credit Account and Savings Account classes correctly, but what I'm getting stuck with is the user defined event to display the error message, and I'm getting confused when I try to get it all to work off my GUI. Some buttons and functions work while others kinda don't :confused: ...and I'm losing so much sleep over it and it's probably something really minor (to you lol) My interface consists of textboxes(AccName, AccNum & Amount to specify the amount you deposit or withdraw) Radio Buttons (Credit & Savings to choose account type. Deposit & Withdraw to choose transaction) Buttons (Clear, Confirm, Exit) Again, any help, tips, pointers, links or anything that would help or point me in the right direction would be greatly appreciated. Thank you

Member Avatar for iamthwee

Well how can we diagnose the problem without seeing the code. Post it here!

Hi everyone!

Yeah sorry about that...maybe posting the code would be a good idea huh?! lol

Sooooo sorry if I post it wrong...

First Class - Credit Account

Public Class Credit_Account

    Private AccountName As String       'Customer's Account Name
    Private AccountNumber As Integer   'Customer's Account Number
    Protected Balance As Double         'Customer's Account Balance

    Public Sub New(ByVal Nm As String, ByVal Bal As Double)
        AccountName = Nm
        Balance = Bal
    End Sub

    Property AccName() As String
        Get
            Return AccountName
        End Get
        Set(ByVal Value As String)
            AccountName = Value
        End Set
    End Property

    Property AccNumber() As Integer
        Get
            Return AccountNumber
        End Get
        Set(ByVal Value As Integer)
            AccountNumber = Value
        End Set
    End Property

    ReadOnly Property AccountBal() As Double
        Get
            Return Balance
        End Get
    End Property

    Public Overridable Sub Deposit(ByVal Amount As Double)
        Balance += Amount
    End Sub

    Public Overridable Sub Withdraw(ByVal Amount As Double)
        Balance -= Amount
    End Sub
    Public Overridable Sub Display()
        Console.WriteLine("Name=" & AccountName & ", " & "Balance=" & Balance)
    End Sub

    Public Sub ChangeName(ByVal newName As String)
        AccountName = newName
    End Sub
    ' Initial balance is zero for each new instance
    Public Sub New()
        Balance = 0
    End Sub
End Class

Second Class - Savings Account

Public Class Saving_Account
    Inherits Credit_Account

    Public Sub New(ByVal Nm As String, _
                       ByVal Bal As Double)

        MyBase.New(Nm, Bal)

    End Sub
    Public Overrides Sub Withdraw(ByVal Amount As Double)
        If Amount <= Balance Then  ' Use balance, inherited from base class
            MyBase.Withdraw(Amount)    ' Call Withdraw, inherited from base class
        End If
    End Sub

    Public Overrides Sub Display()
        MyBase.Display()           ' Call Display, inherited from base class
        Console.WriteLine("There are insufficient funds to complete this transaction." & vbCrLf _
        & "This account cannot have a negative balance.", "Transaction Error")
    End Sub
End Class

Then like I said above, I have my form with buttons, radio buttons and textboxes...I have some code written for my form, but it's all messed up so I thought I'd better not post it :D

I'm unsure of where the RaiseEvent code is supposed to go to "Raise the user defined error message when the user tries to overdraw on the savings account"...and any hints on what I should be trying to write on my 'Confirm' button, on my form to get everything to work that would be cool...so far, when you click on it, it just deposits money into the credit account and shows the running balance. I'm working on the data validation part but again, some parts don't go while some parts do???!!!! AAAAAAAAAARGH....

Thanks for taking the time to give me some much needed advice...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.