Results 1 to 11 of 11

Thread: Homework Problem?? *RESOLVED*

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131

    Question Homework Problem?? *RESOLVED*

    Here is what I have to build:
    Checking Account
    I am stuck on my Withdrawal values and Balance. I think I can figure out Balance if I can get my Withdrawals to work correct. Withdrawals is just the Transaction Amount when radio button Check is checked. I have it represented as WT = WT + TA.

    My problem is TA is retaining it's value everytime I click anything. I have it as TA = Val(txtTransaction.Text).

    When I type 300 in TA and have the radio Deposit checked, then everything works fine. My txtDeposits.Text displays right and so does txtBalance.Text, but when I click Next and reset TA, and check radio Check, then somehow it it using the value I entered before and then calculating Withdrawals. I think it might be the way I have set up the variables but really don't know. This is the code I have:
    VB Code:
    1. Option Strict On
    2. Public Class Form1
    3.     Inherits System.Windows.Forms.Form
    4.  
    5.     ' Assignment 3:     Checking Account
    6.     ' Programmer:       Brad von Oven
    7.     ' Date:             June 12, 2004
    8.     ' Purpose:          Create an application to display a checkbook.  
    9.     '                   The user enters a transaction amount in a text
    10.     '                   box and selects a button for deposit or check.  
    11.     '                   An update button performs validation on the text
    12.     '                   box to make sure there is a number greater
    13.     '                   than 0 in the box.  If the entry is not OK then
    14.     '                   use a message box to tell the user and reset the
    15.     '                   focus back to the text box and stop the sub
    16.     '                   procedure.  When the entry is acceptable the
    17.     '                   update button evaluates the transaction and
    18.     '                   adds deposits while subtracting checks from the
    19.     '                   balance.  If the check is greater than the
    20.     '                   balance a service charge of $25 is applied
    21.     '                   instead of the check amount.  Keep track of the
    22.     '                   balance, total amount in dollars of checks,
    23.     '                   deposits and service charges.  Display the
    24.     '                   results.  Option strict is on.
    25.  
    26.     ' Declare variables and constants
    27.     Dim TA, BL, WT, CH, DP, DX As Double
    28.     Const CA As Double = 25
    29.     ' TA is txtTransaction
    30.     ' BL is txtBalance
    31.     ' WT is txtWithdrawals
    32.     ' CH is txtCharges
    33.     ' DP is txtDeposits
    34.     ' CA is Charge Amount
    35.  
    36.  
    37.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    38.  
    39.     End Sub
    40.  
    41.     Private Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
    42.         txtTransaction.Text = ""
    43.         txtTransaction.Focus()
    44.     End Sub
    45.  
    46.     Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
    47.         TA = Val(txtTransaction.Text)
    48.         DP = DP + TA
    49.         DX = DP
    50.         WT = WT + TA
    51.         CH = CH + CA
    52.         BL = ((DX - TA) - WT)
    53.        
    54.         If txtTransaction.Text <= "0" Then
    55.             MessageBox.Show("Please enter an amount > 0.", "Error")
    56.             txtTransaction.Focus()
    57.         End If
    58.  
    59.  
    60.         If radDeposit.Checked Then
    61.             txtDeposits.Text = (DP).ToString("c")
    62.             txtBalance.Text = (DP).ToString("c")
    63.  
    64.         End If
    65.        
    66.         If radCheck.Checked Then
    67.             txtWithdrawals.Text = (WT).ToString("c")
    68.             txtBalance.Text = (BL).ToString("c")
    69.         End If
    70.  
    71.     End Sub
    72. End Class
    Last edited by twisted; Jun 14th, 2004 at 01:09 PM.
    Twisted

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    This is an assignment to help you learn VB.NET, one object of which is to teach you how to debug programmes. So all I am going to do is give you a push.

    Go through your code systematically.


    First ....Your assignment tells you to validate the textbox entry and then "Stop" (that really should be Exit) the sub. Now think, should you check that textbox before or after you start using it's contents?

    Second .... Your validating code begins

    If txtTransaction.Text <= "0" Then

    Can you see something wrong with that?


    Third.... In your code

    If txtTransaction.Text <= "0" Then
    MessageBox.Show("Please enter an amount > 0.", "Error")
    txtTransaction.Focus()
    End If

    You are supposed to exit the sub as well as return to the textBox.

    That will do for now.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  3. #3
    Lively Member
    Join Date
    Nov 2003
    Location
    Chicagoland
    Posts
    92
    OK, just a couple of things to kind of point you in the right direction.

    Usually if you are going to do validation on a textbox, you do that before you assign its value to a variable. By the looks of your assignment, you want to make sure that a positive number was entered and not any text, so you need a beefier validation other than > "0".

    What is DX? And why don't you just use DP instead?

    As for why TA seems to be using the previous value, I don't know. It might have to do with DX.

    Personally, I would split the functionality up and and calculate the balance based on whether it is a check or a deposit.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    Ok I wrote down how things should work. Does this look OK??

    Update Click Event:

    1. Declare variable for transaction amount.

    2. Validate input

    a. If not number or = 0 then display message box, clear box and reset focus

    3. If deposit transaction then add amount to total deposits and balance

    4. If check transaction then

    a. If amount > balance then display message box for insufficient funds, subtract service charge from balance and add service charge to total charges

    b. Else enough funds, subtract amount from balance, add amount to total checks

    5. Display results (balance, deposits, checks, charges)
    Twisted

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    OK this is what I wrote: But it still calculates funny. Everytime I enter something in txtTransaction box it justs add it to the next value I type in. Say I type in 300 and hit radDeposit it will work. But when I type in 300 and hit radCheck it displays 600 in Withdrawals. WHY? I think it is storing TA at last values (300) then calculating. WT=WT+TA where TA should be just 300, but its adding the last 300 and making it 600. Does anyone understand what I mean??

    VB Code:
    1. Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
    2.         TA = Val(txtTransaction.Text)
    3.         DP = DP + TA
    4.         WT = WT + TA
    5.         CH = CH + CA
    6.         BL = BL - TA
    7.         CC = CC - CA
    8.  
    9.         If txtTransaction.Text <= "0" Then
    10.             MessageBox.Show("Please enter an amount > 0.", "Error")
    11.             txtTransaction.Focus()
    12.         End If
    13.  
    14.         If radDeposit.Checked Then
    15.             txtDeposits.Text = (DP).ToString("c")
    16.             txtBalance.Text = (DP).ToString("c")
    17.         End If
    18.  
    19.         If radCheck.Checked And txtTransaction.Text > txtBalance.Text Then
    20.             MessageBox.Show("$25 service charge applied.", "Insufficient Funds Penalty")
    21.             txtBalance.Text = (CC).ToString("c")
    22.             txtCharges.Text = (CH).ToString("c")
    23.             txtTransaction.Focus()
    24.         Else
    25.             If radCheck.Checked And txtTransaction.Text < txtBalance.Text Then
    26.                 txtWithdrawals.Text = (WT).ToString("c")
    27.                 txtBalance.Text = (BL).ToString("c")
    28.             End If
    29.         End If
    30.     End Sub
    Twisted

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi twisted.

    I am begining to wonder if you are just fooling with us. You have ignored previous guidance entirely. Until you make an attempt to follow what you are told I, for one, am not going to respond. It is a waste of time.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    Oops! I must be really newbish then, cause without seeing a code example I'm lost. I tried to listen to what you said but don't know what you're talking about.
    Twisted

  8. #8
    Lively Member
    Join Date
    Nov 2003
    Location
    Chicagoland
    Posts
    92
    Alright, simple money management here: You only have one balance. It is what is in your account. Any withdrawals and deposits should be refelected in the single balance, i.e. what is in your account. If you deposit, it should get bigger. If you withdraw, it should get smaller. Your transaction should affect the balance whether it is a deposit or a check.

    Let's not worry about anything but the balance for now. Get this working correctly, then add the other functionality.

    Let's assume your balance starts at zero.

    Deposit $300, Balance = $300 (add 300 to balance)

    Check $50, Balance = $250 (subtract 50 from balance)

    Deposit $5, Balance = $255 (add 5 to balance)

    Check $200, Balance = $55 (subtract 200 from balance)

    You will need to know what radio button is checked before you do any arithmetic.

    Get this working then worry about the rest.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    Originally posted by shadowfyre
    Alright, simple money management here: You only have one balance. It is what is in your account. Any withdrawals and deposits should be refelected in the single balance, i.e. what is in your account. If you deposit, it should get bigger. If you withdraw, it should get smaller. Your transaction should affect the balance whether it is a deposit or a check.

    Let's not worry about anything but the balance for now. Get this working correctly, then add the other functionality.

    Let's assume your balance starts at zero.

    Deposit $300, Balance = $300 (add 300 to balance)

    Check $50, Balance = $250 (subtract 50 from balance)

    Deposit $5, Balance = $255 (add 5 to balance)

    Check $200, Balance = $55 (subtract 200 from balance)

    You will need to know what radio button is checked before you do any arithmetic.

    Get this working then worry about the rest.
    OK I'm gonna try my best to follow you. My deposits are working fine and add great, but anytime I change to a check it doesn't minus at all. Here is what I got I started from scratch:
    VB Code:
    1. Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
    2.         TA = Val(txtTransaction.Text)
    3.         DP = DP + TA
    4.         WT = WT + TA
    5.         BL = BL - TA
    6.  
    7.         If radDeposit.Checked Then
    8.             txtDeposits.Text = (DP).ToString("c")
    9.             txtBalance.Text = (DP).ToString("c")
    10.         End If
    11.  
    12.         If radCheck.Checked Then
    13.             txtWithdrawals.Text = (WT).ToString("c")
    14.             txtBalance.Text = (BL).ToString("c")
    15.         End If
    16.  
    17.     End Sub
    Twisted

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    HOLY SMACKS!!! I got it!
    VB Code:
    1. Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
    2.         TA = Val(txtTransaction.Text)
    3.  
    4.         If radDeposit.Checked Then
    5.             DP = DP + TA
    6.             txtDeposits.Text = (DP).ToString("c")
    7.             txtBalance.Text = (DP - WT).ToString("c")
    8.         End If
    9.  
    10.         If radCheck.Checked Then
    11.             WT = WT + TA
    12.             txtWithdrawals.Text = (WT).ToString("c")
    13.             txtBalance.Text = (DP - WT).ToString("c")
    14.         End If
    15.  
    16.     End Sub
    It is calculating perfect! Now for the:
    VB Code:
    1. If txtTransaction.Text <= "0" Then
    2.             MessageBox.Show("Please enter an amount > 0.", "Error")
    3.             txtTransaction.Focus()
    4.         End If
    What do I add saying that it cannot be text?
    Twisted

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    OK first off my whole problem was my expressions DP = DP + TA needed to be under an If statement, not just hanging up under my btn_click. Now that I have figured that out I have gotten everything working. Thanks for the help guys! The only thing I need is how to write my MessageBox Error. I will highlight it in RED, it works but how do I change it so it will display if people enter Text. Thanks and here's my code:

    VB Code:
    1. Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
    2.         TA = Val(txtTransaction.Text)
    3.         txtWithdrawals.Text = Format(WT, "c")
    4.         txtCharges.Text = Format(CH, "c")
    5.  
    6.         [COLOR=RED]If txtTransaction.Text <= "0" Then
    7.             MessageBox.Show("Please enter an amount > 0.", "Error")
    8.             txtTransaction.Focus()
    9.         End If[/COLOR]
    10.  
    11.         If radDeposit.Checked Then
    12.             DP = DP + TA
    13.             txtDeposits.Text = (DP).ToString("c")
    14.             txtBalance.Text = ((DP - WT) - CH).ToString("c")
    15.         End If
    16.  
    17.         If radCheck.Checked And TA > ((DP - WT) - CH) Then
    18.             MessageBox.Show("$25 service charge applied.", "Insufficient Funds Penalty")
    19.             CH = CH + CA
    20.             BL = ((DP - WT) - CH)
    21.             txtCharges.Text = (CH).ToString("c")
    22.             txtBalance.Text = (BL).ToString("c")
    23.             txtTransaction.Focus()
    24.         Else
    25.             If radCheck.Checked And TA < ((DP - WT) - CH) Then
    26.                 WT = WT + TA
    27.                 txtWithdrawals.Text = (WT).ToString("c")
    28.                 txtBalance.Text = ((DP - WT) - CH).ToString("c")
    29.             End If
    30.         End If
    31.  
    32.  
    33.     End Sub
    Twisted

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width