|
-
Jun 14th, 2004, 09:20 AM
#1
Thread Starter
Addicted Member
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:
Option Strict On
Public Class Form1
Inherits System.Windows.Forms.Form
' Assignment 3: Checking Account
' Programmer: Brad von Oven
' Date: June 12, 2004
' Purpose: Create an application to display a checkbook.
' The user enters a transaction amount in a text
' box and selects a button for deposit or check.
' An update button performs validation on the text
' box to make sure there is a number greater
' than 0 in the box. If the entry is not OK then
' use a message box to tell the user and reset the
' focus back to the text box and stop the sub
' procedure. When the entry is acceptable the
' update button evaluates the transaction and
' adds deposits while subtracting checks from the
' balance. If the check is greater than the
' balance a service charge of $25 is applied
' instead of the check amount. Keep track of the
' balance, total amount in dollars of checks,
' deposits and service charges. Display the
' results. Option strict is on.
' Declare variables and constants
Dim TA, BL, WT, CH, DP, DX As Double
Const CA As Double = 25
' TA is txtTransaction
' BL is txtBalance
' WT is txtWithdrawals
' CH is txtCharges
' DP is txtDeposits
' CA is Charge Amount
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
txtTransaction.Text = ""
txtTransaction.Focus()
End Sub
Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
TA = Val(txtTransaction.Text)
DP = DP + TA
DX = DP
WT = WT + TA
CH = CH + CA
BL = ((DX - TA) - WT)
If txtTransaction.Text <= "0" Then
MessageBox.Show("Please enter an amount > 0.", "Error")
txtTransaction.Focus()
End If
If radDeposit.Checked Then
txtDeposits.Text = (DP).ToString("c")
txtBalance.Text = (DP).ToString("c")
End If
If radCheck.Checked Then
txtWithdrawals.Text = (WT).ToString("c")
txtBalance.Text = (BL).ToString("c")
End If
End Sub
End Class
Last edited by twisted; Jun 14th, 2004 at 01:09 PM.
Twisted
-
Jun 14th, 2004, 09:42 AM
#2
PowerPoster
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.
-
Jun 14th, 2004, 09:56 AM
#3
Lively Member
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.
-
Jun 14th, 2004, 10:33 AM
#4
Thread Starter
Addicted Member
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)
-
Jun 14th, 2004, 10:59 AM
#5
Thread Starter
Addicted Member
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:
Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
TA = Val(txtTransaction.Text)
DP = DP + TA
WT = WT + TA
CH = CH + CA
BL = BL - TA
CC = CC - CA
If txtTransaction.Text <= "0" Then
MessageBox.Show("Please enter an amount > 0.", "Error")
txtTransaction.Focus()
End If
If radDeposit.Checked Then
txtDeposits.Text = (DP).ToString("c")
txtBalance.Text = (DP).ToString("c")
End If
If radCheck.Checked And txtTransaction.Text > txtBalance.Text Then
MessageBox.Show("$25 service charge applied.", "Insufficient Funds Penalty")
txtBalance.Text = (CC).ToString("c")
txtCharges.Text = (CH).ToString("c")
txtTransaction.Focus()
Else
If radCheck.Checked And txtTransaction.Text < txtBalance.Text Then
txtWithdrawals.Text = (WT).ToString("c")
txtBalance.Text = (BL).ToString("c")
End If
End If
End Sub
-
Jun 14th, 2004, 11:33 AM
#6
PowerPoster
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.
-
Jun 14th, 2004, 11:52 AM
#7
Thread Starter
Addicted Member
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.
-
Jun 14th, 2004, 11:54 AM
#8
Lively Member
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.
-
Jun 14th, 2004, 12:05 PM
#9
Thread Starter
Addicted Member
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:
Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
TA = Val(txtTransaction.Text)
DP = DP + TA
WT = WT + TA
BL = BL - TA
If radDeposit.Checked Then
txtDeposits.Text = (DP).ToString("c")
txtBalance.Text = (DP).ToString("c")
End If
If radCheck.Checked Then
txtWithdrawals.Text = (WT).ToString("c")
txtBalance.Text = (BL).ToString("c")
End If
End Sub
-
Jun 14th, 2004, 12:23 PM
#10
Thread Starter
Addicted Member
HOLY SMACKS!!! I got it!
VB Code:
Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
TA = Val(txtTransaction.Text)
If radDeposit.Checked Then
DP = DP + TA
txtDeposits.Text = (DP).ToString("c")
txtBalance.Text = (DP - WT).ToString("c")
End If
If radCheck.Checked Then
WT = WT + TA
txtWithdrawals.Text = (WT).ToString("c")
txtBalance.Text = (DP - WT).ToString("c")
End If
End Sub
It is calculating perfect! Now for the:
VB Code:
If txtTransaction.Text <= "0" Then
MessageBox.Show("Please enter an amount > 0.", "Error")
txtTransaction.Focus()
End If
What do I add saying that it cannot be text?
-
Jun 14th, 2004, 01:00 PM
#11
Thread Starter
Addicted Member
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:
Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
TA = Val(txtTransaction.Text)
txtWithdrawals.Text = Format(WT, "c")
txtCharges.Text = Format(CH, "c")
[COLOR=RED]If txtTransaction.Text <= "0" Then
MessageBox.Show("Please enter an amount > 0.", "Error")
txtTransaction.Focus()
End If[/COLOR]
If radDeposit.Checked Then
DP = DP + TA
txtDeposits.Text = (DP).ToString("c")
txtBalance.Text = ((DP - WT) - CH).ToString("c")
End If
If radCheck.Checked And TA > ((DP - WT) - CH) Then
MessageBox.Show("$25 service charge applied.", "Insufficient Funds Penalty")
CH = CH + CA
BL = ((DP - WT) - CH)
txtCharges.Text = (CH).ToString("c")
txtBalance.Text = (BL).ToString("c")
txtTransaction.Focus()
Else
If radCheck.Checked And TA < ((DP - WT) - CH) Then
WT = WT + TA
txtWithdrawals.Text = (WT).ToString("c")
txtBalance.Text = ((DP - WT) - CH).ToString("c")
End If
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|