6 Replies - 1350 Views - Last Post: 25 April 2013 - 09:33 PM Rate Topic: ****- 1 Votes

#1 basicprogramming  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-April 13

Tally Withdrawal and Deposits in Banking Program

Posted 24 April 2013 - 12:04 PM

Hi guys! So I have basic knowledge of programming procedures for Visual Basic 6 but I'm having trouble with one section of a project, and I would really appreciate it if anyone could help or get me heading in the right direction.
I have a banking program, which displays (in text boxes) a current balance, withdrawal, deposit, and final balance. There's also four command buttons: calculate, new, clear, and exit. When I hit the new command button, I'm supposed to able to calculate the number of withdrawals and number of deposits that have occurred and display them in separate text boces. I can't seem to figure this out, but here's what I've tried before.

cmdNew is the command box captioned "New" that should tally the deposits and withdrawals made so far.
txtDeposit is the text box that allows the user to enter the amount of money that they would like to deposit.
txtWithdraw is the text box that allows the user to enter the amount of money that they would like to withdraw
txtDepositCount is the text box that displays the number of times a user has made a deposit
txtWithdrawalCount is the text box that displays the number of times a user had made a withdrawal

I'm not getting error messages necessarily, but the program just doesn't work. I either end up with both the txtWithdrawalCount.Text and txtDepositCount.Text being 1 and not changing after another transaction is made, or nothing happening at all, or causing an infinite loop.

Private Sub cmdNew_Click()

Dim Deposit as Integer
Deposit = Val(txtDepositCount.Text)
Deposit = 0

Do
If txtDeposit.Text = Blank Then
Deposit = Deposit
Else
Count = Count + 1
End If
Loop

Dim Withdrawal as Integer
Withdrawal = Val(txtWithdrawalCount.Text
Withdrawal = 0

Do
If txtWithdrawal.Text = Blank Then
Withdrawal = Withdrawal
Else
Withdrawal = Withdrawal + 1
End If
Loop

End Sub


Thanks in advance for the help!
-Amateur Programmer

Oops sorry! Line 11 should have said the following instead.
[Deposit = Deposit + 1]

This post has been edited by modi123_1: 24 April 2013 - 12:13 PM
Reason for edit:: fixed botched code tag


Is This A Good Question/Topic? 0
  • +

Replies To: Tally Withdrawal and Deposits in Banking Program

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9088
  • View blog
  • Posts: 34,134
  • Joined: 12-June 08

Re: Tally Withdrawal and Deposits in Banking Program

Posted 24 April 2013 - 12:12 PM

... any particular reason why you put a bracket around each line?
Was This Post Helpful? 1
  • +
  • -

#3 basicprogramming  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-April 13

Re: Tally Withdrawal and Deposits in Banking Program

Posted 24 April 2013 - 12:13 PM

Sorry about that! I misunderstood the instruction that tells you to "put tags around your code: [code]."
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3358
  • View blog
  • Posts: 11,371
  • Joined: 12-December 12

Re: Tally Withdrawal and Deposits in Banking Program

Posted 24 April 2013 - 12:19 PM

What's with all the square brackets?

This can't be your actual code? There is a syntax error here:

Withdrawal = Val(txtWithdrawalCount.Text <<< missing )


You have do..loops without any condition, so they don't DO anything.

Statements like this:

Deposit = Val(txtDepositCount.Text)
Deposit = 0

are ineffective: they might read a value from a textbox, but then immediately set the variable to 0.

I assume Blank is defined elsewhere?

You should post your actual code. But even then, there is nothing in your code that changes the text in a textbox, so you'll need to post relevant code.

But if you want to increase the number held in a textbox then you'll need code like:

Dim tempVal As Integer
tempVal = Val(txtSome.Text)
tempVal = tmpVal + 1
txtSome.Text = CStr(tempVal)

Was This Post Helpful? 2
  • +
  • -

#5 basicprogramming  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-April 13

Re: Tally Withdrawal and Deposits in Banking Program

Posted 24 April 2013 - 12:28 PM

Thank you for the input! I really appreciate it. As I said, I'm really just getting started with programming, so I apologize if I'm making some basic mistakes.
I haven't defined the variable "Blank" actually, I just meant that the following should occur when that text box is blank.

Should I use this instead?

If txtDeposit.Text = "" Then


Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3358
  • View blog
  • Posts: 11,371
  • Joined: 12-December 12

Re: Tally Withdrawal and Deposits in Banking Program

Posted 24 April 2013 - 12:35 PM

View Postbasicprogramming, on 24 April 2013 - 07:28 PM, said:

Thank you for the input! I really appreciate it. As I said, I'm really just getting started with programming, so I apologize if I'm making some basic mistakes.
I haven't defined the variable "Blank" actually, I just meant that the following should occur when that text box is blank.

Should I use this instead?

If txtDeposit.Text = "" Then


Yes, that'll do it.
Was This Post Helpful? 2
  • +
  • -

#7 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Tally Withdrawal and Deposits in Banking Program

Posted 25 April 2013 - 09:33 PM

Quote

If txtDeposit.Text = Blank Then

You can avoid a lot of ambiguities in your code by putting "Option Explicit" at the top of each code page. This line will raise an error if you do, which will make it easier to troubleshoot the problem. Otherwise, VB does this behind the scenes:
Dim Blank as Variant
This is called "implicit variable declaration"; you have "implied" that you want this variable by referring to it. Not so good if you aren't aware that this has been done.

Better yet, set up VB so it always puts "Option Explicit" at the top of each code window for you. Go to Tools/Options and check "Require Variable Declaration". (While you're at it, uncheck "Auto Syntax Check". You'll still get automatic syntax checking, but bad syntax will just turn red instead of popping up an annoying message window.) Hit Ok, and from now on, all your code windows will have "Option Explicit" at the top.

This post has been edited by BobRodes: 25 April 2013 - 09:35 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1