GIDForums  

Go Back   GIDForums > Computer Programming Forums > .NET Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-Apr-2009, 23:51
boblc123 boblc123 is offline
New Member
 
Join Date: Apr 2009
Posts: 3
boblc123 is on a distinguished road
Question

Help coding function Procedures in VB 2008


Hey guys if anyone could help me this would be extremely appreciated. My homework assignment is to take a checking account program that we've already written and add function procedures to it. The exact instructions are: Write function procedures for processing deposits, checks, and service charges. Deposit function adds the deposit to the balance; the check subtracts the transaction amount from the balance; the service charge function subtracts the amount from the balance. each of the functions must return the updated balance.

Again, this program currently works as it is right now but we have to tweak the code to include function procedures as per the above mentioned directions.

VB / Visual Basic Code:
Private Sub CalculateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateToolStripMenuItem.Click
Try
If Decimal.Parse(AmountTextBox.Text) > 0 Then
'assigns the variable
amountDecimal = Decimal.Parse(AmountTextBox.Text)


'checks to see which Radio button is checked and performs calculations
If DepositRadioButton.Checked Then
newbalanceDecimal += amountDecimal
totalamountdepositsDecimal += amountDecimal
totaldepositsInteger += 1

ElseIf CheckRadioButton.Checked Then
'checks to see if balance is greater than the amount entered
If newbalanceDecimal >= amountDecimal Then
newbalanceDecimal -= amountDecimal
totalchecksInteger += 1
totalamountchecksDecimal += amountDecimal

'If amount entered is more than the balance then give an error and deduct 10 bux from balance
Else
MessageBox.Show("Insufficient Funds")
newbalanceDecimal -= 10
totalamountchecksDecimal += 10
totalservicechargesInteger += 1

End If

ElseIf ServiceChargeRadioButton.Checked Then
newbalanceDecimal -= amountDecimal
totalamountservicechargesDecimal += amountDecimal
totalservicechargesInteger += 1

'If no radio button is selected then give an error
Else
MessageBox.Show("You must select either Deposit, Checking, or Service Charge" _
, "Selection Required", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

'displays the final total in textbox
NewBalanceTextBox.Text = newbalanceDecimal.ToString("C")




'enable the summary menu
SummaryToolStripMenuItem.Enabled = True

'if numeric values are not entered then give an error

Else
MessageBox.Show("You CANNOT enter negative numbers into the Amount of Transaction textbox" _
, "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

Catch
MessageBox.Show("You must enter numbers into the Amount textbox", "Invalid Input" _
, MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try
End Sub
Last edited by admin : 11-Apr-2009 at 00:11. Reason: Please insert your example VB codes between [VB] and [/VB] tags
  #2  
Old 11-Apr-2009, 03:49
erniegerdie erniegerdie is offline
Awaiting Email Confirmation
 
Join Date: Feb 2004
Location: England
Posts: 93
erniegerdie has a spectacular aura abouterniegerdie has a spectacular aura about

Re: Help coding function Procedures in VB 2008


Which bit do you want help with?
  #3  
Old 11-Apr-2009, 12:17
boblc123 boblc123 is offline
New Member
 
Join Date: Apr 2009
Posts: 3
boblc123 is on a distinguished road

Re: Help coding function Procedures in VB 2008


I want help with putting the deposit radio button statement in a function procedure. Once someone shows me how to do that, i'll be able to do the rest myself.
  #4  
Old 15-Apr-2009, 10:05
erniegerdie erniegerdie is offline
Awaiting Email Confirmation
 
Join Date: Feb 2004
Location: England
Posts: 93
erniegerdie has a spectacular aura abouterniegerdie has a spectacular aura about

Re: Help coding function Procedures in VB 2008


Your methods are pretty much highlighted by your comments.

You could alter your main CalculateToolStripMenuItem_Click method to call the new methods.

VB / Visual Basic Code:
...
If DepositRadioButton.Checked Then
      PerformDeposit()
ElseIf CheckRadioButton.Checked Then
...

The Deposit section could be something like this (excuse my VB I only code in C#):
VB / Visual Basic Code:
Private Sub PerformDeposit(ByVal amountDecimal As System.Decimal) 
   newbalanceDecimal += amountDecimal
   totalamountdepositsDecimal += amountDecimal
   totaldepositsInteger += 1
End Sub

Is that the kind of thing you are looking to do?
  #5  
Old 17-May-2009, 00:14
boblc123 boblc123 is offline
New Member
 
Join Date: Apr 2009
Posts: 3
boblc123 is on a distinguished road

Re: Help coding function Procedures in VB 2008


Quote:
Originally Posted by erniegerdie
Your methods are pretty much highlighted by your comments.

You could alter your main CalculateToolStripMenuItem_Click method to call the new methods.

VB / Visual Basic Code:
...
If DepositRadioButton.Checked Then
      PerformDeposit()
ElseIf CheckRadioButton.Checked Then
...

The Deposit section could be something like this (excuse my VB I only code in C#):
VB / Visual Basic Code:
Private Sub PerformDeposit(ByVal amountDecimal As System.Decimal) 
   newbalanceDecimal += amountDecimal
   totalamountdepositsDecimal += amountDecimal
   totaldepositsInteger += 1
End Sub

Is that the kind of thing you are looking to do?

I appologize that it took me so long to reply, but yes, that is exactly what i needed and it worked fine. I really appreciate the help and now that I've seen an example I understand it and can do it on my own now. thanks again!
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
run script command on ns2.26 newbie06 Computer Software Forum - Linux 65 19-Aug-2009 08:50
Problem executing nam-1.13 RodolfoAlvizu Computer Software Forum - Linux 20 28-Feb-2009 16:23
Free a malloc returned in a function james_bond C Programming Language 4 06-Jan-2008 14:59
Need Help with input files. Efferus C++ Forum 2 24-Nov-2007 17:19
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 14:12

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:46.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.