Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

VB Banking System


  • Please log in to reply

#1
Wanjii

Wanjii

    New Member

  • Member
  • Pip
  • 2 posts
Help!
I 'm obviously new to programming and I need help. I'm trying to design a banking system in VB. The withdrawal mechanism is giving me trouble.
My requirements are:
The systen should check your name and if the account name exists and is correct, proceed to check that your account number and PIN number are correct and match.
Once this is done and no fields are blank, the system should then allow the person to withdraw money.
The snag comes when I try to ensure that a customer cannot withdraw more money than they have.
With my currrent code if I add the "If withdrawal > oldbalance Then MsgBox a" bit then it messes up the if statements and i dont get the error message for wrong PIN or Account number which is in the Else if statement further on.
But if I remove the wrong PIN or Account number code I get the error message saying there are insuffcient funds but the system still withdraws leaving a negative account balance.
If I remove the checking code, the validation systen works great but gives me an inaccurate receipt and alows me to withdraw money from nonexistent accounts! :whistling:

Here is my code:

'the button which sets the ball rolling
Private Sub Cmdsave_Click()

Dim mode As String
Dim a As String


TxtDate.Text = Date

'the error message for attempting to overdraw the account
a = " The withdrawal amount is greater than the Account Balance. Please enter a lower figure or see the Bank manager for Overdraft Facilities"

'checks if the withdrawal is in cash or cheque
If ChkCash.value = 1 Then
mode = "Cash"
End If
If ChkCheque.value = 1 Then
mode = "Cheque"
End If
Txtmode.Text = mode

'validation code to ensure no fields are left blank.
If TxtName.Text = "" Then
MsgBox "Please enter Account Details."
cancel = True
TxtName.SetFocus
Else

If TxtWAmt.Text = "" Then
MsgBox "Please Enter the amount to be withdrawn"
cancel = True
TxtWAmt.SetFocus
Else

If Txtmode.Text = "" Then
MsgBox "Please select a mode of payment"
cancel = True
Else

'code to check whether the account name exists in the system.
Adodc2.Recordset.MoveFirst
Adodc2.Recordset.Find "Name='" & TxtName.Text & "'"
If Adodc2.Recordset.EOF = True Then
MsgBox "Invalid Account Holder"
Else

'code to check whether PIN & Account numbers are correct
If TxtAccountNo.Text = Adodc2.Recordset!AccountNo And TxtPIN.Text = Adodc2.Recordset!PINNo Then

Dim oldbalance As Double
Dim withdrawal As Double
Dim newbalance As Double

oldbalance = TxtOldAcBal.Text
withdrawal = TxtWAmt.Text
newbalance = oldbalance - withdrawal
txtNewAcBal.Text = newbalance

'validation code to prevent withdrawing more than the current account balance
If withdrawal > oldbalance Then
MsgBox a
cancel = True
TxtWAmt.SetFocus

Else

'if the above is fine, then record the withdrawal in the withdrawal records
Adodc1.Recordset.Save
MsgBox "Withdrawal Recorded"

' then change the account balance to the new balance
Adodc2.Recordset.Save
CmdSlip.Enabled = True

'Reset the withdrawal panel
Adodc2.Recordset.AddNew


'Code to give error message if the wrong PIN or Account number is put in.
Else

MsgBox "Invalid Account Number or PIN Number, try again!"
TxtAccountNo.SetFocus


End If
End If
End If
End If
End If
End If
End If
End Sub


'the code that generates the reciept
Private Sub CmdSlip_Click()
TxtSliph.Visible = True

TxtSlipd.Visible = True
TxtSliph.Text = " KENYA COMMERCIAL BANK " & vbCrLf & _
vbCrLf & _
" WITHDRAWAL SLIP" & vbCrLf
TxtSlipd.Text = "Date: " & Date & " Time: " & Time & vbCrLf & _
vbCrLf & _
"Account Number: " & TxtAccountNo.Text & vbCrLf & _
vbCrLf & _
"Amount Withdrawn: " & TxtWAmt.Text




End Sub

Private Sub Form_Load()

Adodc1.Recordset.AddNew

End Sub
  • 0

Advertisements


#2
Ctrl_Alt_Del

Ctrl_Alt_Del

    Member

  • Member
  • PipPip
  • 74 posts
Your code is very hard to read. It would help if you put it in code tags.

Check to see what the value of oldbalance and withdrawal is after you assign them the values from the text boxes. You should actually be doing an explicit conversion from text to double when you assign the values from the text boxes to the double variables.


Also I'm not sure how you actually have it structured in your code but if you actually do have all of those elses with ifs inside the elses it would be much more read readable and a bit more efficient if you changed the elses to elseif.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP