Alex_2011 0 Light Poster

How are you,

I need some help with the following code (Attached Form1 & AccountClass).
I am trying to figure out the following:

- Figure out the code in ButtonWithdrawal when the amount is bigger than 0.

- Show the (Balance) in ButtonBalanceInq.

- Show the List of transactions in (ButtonListTransactions).


I commented out the things that I could not figure out and I really appreciate the help and thank you in advance.

Public Class Form1
    Private AllAccount(-1) As AccountClass


    Private Sub ButtonCustomerInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCustomerInfo.Click
        Dim NewAccount As New AccountClass
        ReDim Preserve AllAccount(AllAccount.Length)
        AllAccount(AllAccount.Length - 1) = NewAccount
        Dim LastName As String = InputBox("Last Name")
        Dim FirstName As String = InputBox("First Name")
        Dim AccountNumber As String = InputBox("Account Number")
        NewAccount.LastName = LastName
        NewAccount.FirstName = FirstName
        NewAccount.AccountNumber = AccountNumber

    End Sub

    Private Sub ButtonDeposit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDeposit.Click
        Dim WhatAccout As Integer = Integer.Parse(InputBox("Account Number") - 1)
        Dim TextEntered As String = InputBox("Enter Amount of Deposit")
        Dim ThisDeposit As Decimal = Decimal.Parse(TextEntered)
        If ThisDeposit > 0 Then
            AllAccount(WhatAccout).Deposit(ThisDeposit)
        Else
            MessageBox.Show("Problem with transaction")
        End If
    End Sub


    Private Sub ButtonWithdrawal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonWithdrawal.Click
        Dim WhatAccout As Integer = Integer.Parse(InputBox("Account Number") - 1)
        Dim TextEntered As String = InputBox("Enter amount to withdraw")
        Dim AmountToWithdraw As Decimal = Decimal.Parse(TextEntered)
        If AmountToWithdraw = 0 Then
            MessageBox.Show("You must enter a positive number")
            '    ElseIf AmountToWithdraw > AllAccount(WhatAccout).Withdrawal Then
            '       MessageBox.Show("Illegal withdrawal. You cannot withdraw more that " & NewAccount.Balance)
        Else
            AllAccount(WhatAccout).Withdrawal(AmountToWithdraw)

        End If
    End Sub

    Private Sub ButtonBalanceInq_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonBalanceInq.Click
        Dim WhatAccount As Integer = Integer.Parse(InputBox("Account number") - 1)
        '   MessageBox.Show("Your balance is " & AllAccount(WhatAccount).ToString)


    End Sub

    Private Sub ButtonListTransactions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonListTransactions.Click
        Dim WhatAccount As Integer = Integer.Parse(InputBox("Account number") - 1)
        ReDim Preserve AllAccount(AllAccount.Length)
        AllAccount(AllAccount.Length - 1) = NewAccount
        Me.ListBoxDisplay.Items.Clear()
        ' Me.ListBoxDisplay.Items.Add(AllAccount.FirstName & vbTab & vbTab & AllAccount.LastName & vbTab & "Account # " & AllAccount.AccountNumber)
        Me.ListBoxDisplay.Items.Add("=====================================")
        ' NewAccount.ShowTransactions(ListBoxDisplay)
    End Sub

    Private Sub ButtonClearDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonClearDisplay.Click
        ListBoxDisplay.Items.Clear()
    End Sub

    Private Sub ButtonExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonExit.Click
        Me.Close()
    End Sub
End Class

And this is the AccountClass code:

Public Class AccountClass
    
    Private FNAme As String
    Property FirstName() As String
        Get
            Return FNAme
        End Get
        Set(ByVal value As String)
            FNAme = value
        End Set
    End Property

    Private LName As String
    Property LastName() As String
        Get
            Return LName
        End Get
        Set(ByVal value As String)
            LName = value
        End Set
    End Property

    Private AccNum As String
    Property AccountNumber() As String
        Get
            Return AccNum
        End Get
        Set(ByVal value As String)
            Const PASSWORD As String = "money"
            Dim PasswordEntered As String = InputBox("Enter Password")
            If PasswordEntered = PASSWORD Then
                AccNum = value
            End If
        End Set
    End Property

    Private Bal As Decimal
    Public ReadOnly Property Balance
        Get
            Return Bal
        End Get
    End Property

    Private Structure Transaction
        Dim Amount As Decimal
        Dim TrasnactionType As String
        Dim TransDateType As String
        Dim OldBal As String
    End Structure

    Private Activity(-1) As Transaction
    Protected Sub AddTransaction(ByVal AmountDeposited As Decimal, ByVal TransactionType As String)
        'Increase size of array by 1
        ReDim Preserve Activity(Activity.Length)
        'Dim integer to hold activity number
        Dim NewTransaction As Integer = Activity.Length - 1
        'Add info to array
        Activity(NewTransaction).Amount = AmountDeposited
        Activity(NewTransaction).OldBal = Balance
        Activity(NewTransaction).TrasnactionType = TransactionType
        Activity(NewTransaction).TransDateType = DateAndTime.Now.ToString
    End Sub


    Public Sub Deposit(ByVal DepositAmt As Decimal)

        If DepositAmt > 0 Then
            Bal += DepositAmt
            AddTransaction(DepositAmt, "Deposit")
        Else
            MessageBox.Show("Error in deposit")
        End If
    End Sub


    Public Sub Withdrawal(ByVal WithdrawalAmount As Decimal)
        If WithdrawalAmount <= Balance Then
            Bal -= WithdrawalAmount
            AddTransaction(WithdrawalAmount, "Withdrawal")
                 Else
            MessageBox.Show("Error in withdrawal")
        End If
    End Sub
    Public Sub ShowTransactions(ByVal DisplayBox As ListBox)

        Dim CurrentTransaction As Transaction
        DisplayBox.Items.Add("Transaction" & vbTab & "Amount" & vbTab & "Balance" & vbTab & "Trans. Date/Time")
        For TransNum As Integer = 0 To Activity.Length - 1
            CurrentTransaction = Activity(TransNum)
            DisplayBox.Items.Add(CurrentTransaction.TrasnactionType & vbTab & vbTab & CurrentTransaction.Amount & vbTab & CurrentTransaction.OldBal & vbTab & CurrentTransaction.TransDateType)
        Next

    End Sub
End Class
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.