none
Visual Basic Checking Account RRS feed

  • Question

  • I'm having problems with coding this visual basic form. It's for a checking account. I got Deposit and Service Charge working but I'm not getting Checking to work. I just need it to pop up a messaging saying "Insufficient Funds: $10.00 Service Charge"

    Public Class CheckingAccount
        ' Declare variables
        Dim EnterAmountDouble As Double
        Dim CurrentBalanceDouble As Double
    
    
        Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles radService.CheckedChanged
    
        End Sub
    
        Private Sub Label3_Click(sender As Object, e As EventArgs) Handles lblBalance.Click
    
        End Sub
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
            ' Clear and reset variables
            EnterAmountDouble = 0
            CurrentBalanceDouble = 0
    
            'Clear and reset textboxes
            lblBalance.Text = String.Empty
            txtAmount.Clear()
    
    
    
        End Sub
    
        Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
            ' Try catch to make sure numbers are in the textbox
    
            Try
                EnterAmountDouble = Double.Parse(txtAmount.Text)
    
            Catch ex As Exception
    
                MessageBox.Show("Must enter a currency ammount", "Data Error")
            End Try
    
            ' If Else statement for type of transaction
            If radDeposit.Checked = True Then
                CurrentBalanceDouble = CurrentBalanceDouble + EnterAmountDouble
            End If
            If radCheck.Checked = True Then
                CurrentBalanceDouble -= EnterAmountDouble
            End If
            If radService.Checked = True Then
                CurrentBalanceDouble -= EnterAmountDouble
            End If
    
            lblBalance.Text = CurrentBalanceDouble.ToString("C")
    
        End Sub
    
        Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
            ' Close the form
            Me.Close()
        End Sub
    End Class


    Tuesday, March 27, 2018 3:14 PM

All replies

  • Hello,

    If you are open to a alternate way look at my code sample.

    https://1drv.ms/u/s!AtGAgKKpqdWjh1mgr8hdKx4IVzpt


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, March 27, 2018 4:25 PM
    Moderator
  • I got Deposit and Service Charge working but I'm not getting Checking to work. I just need it to pop up a messaging saying "Insufficient Funds: $10.00 Service Charge"

    Are you referring to the radCheck option?

    Before doing the actual calculation, test CurrentBalanceDouble to see if it is greater than or equal to EnterAmountDouble.   If it isn't (there is not sufficient funds in the account), then show the message and exit the Sub.  If it is, then skip the message and continue with the calculation.

    https://msdn.microsoft.com/en-us/library/system.windows.forms.messagebox(v=vs.110).aspx
    Only one button is required because you aren't interested in the response to the message - the user has no options.

    https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/exit-statement

    Tuesday, March 27, 2018 8:39 PM
  •  I got Deposit and Service Charge working but I'm not getting Checking to work. I just need it to pop up a messaging saying "Insufficient Funds: $10.00 Service Charge"

    Hi mbotello_spc,

    You said that you got Deposit and Service Charge working, but you didn't get Checking to working. How do you want it to work? Just need to pop up a messaging saying "Insufficient Funds: $10.00 Service Charge"? If yes, you just add messagebox here, like this:

    Try
                EnterAmountDouble = Double.Parse(txtAmount.Text)
    
            Catch ex As Exception
    
                MessageBox.Show("Must enter a currency ammount", "Data Error")
            End Try
    
            ' If Else statement for type of transaction
            If radDeposit.Checked = True Then
    
                CurrentBalanceDouble = CurrentBalanceDouble + EnterAmountDouble
    
            ElseIf radCheck.Checked = True Then
                If CurrentBalanceDouble >= EnterAmountDouble Then
                    CurrentBalanceDouble -= EnterAmountDouble
                Else
                    MessageBox.Show("Insufficient Funds")
                End If
    
            ElseIf radService.Checked = True Then
                If CurrentBalanceDouble >= EnterAmountDouble Then
                    CurrentBalanceDouble -= EnterAmountDouble
                Else
                    MessageBox.Show("Insufficient Funds")
                End If
            End If
            lblBalance.Text = CurrentBalanceDouble.ToString("C")

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 28, 2018 2:53 AM
    Moderator