
08-Oct-2009, 00:21
|
|
New Member
|
|
Join Date: Oct 2009
Location: Montana
Posts: 2
|
|
|
Understanding function procedures
I am learning Visual Basic 2008, and I am having a hard time understanding function procedures. Can someone help me write a function procedure for the transaction?
VB / Visual Basic Code:
Public Class Form1
'Declare module-level variables for summary information.
Private TotalNumberDepositsCountInteger, TotalNumberChecksCountInteger, TotalServiceChargeInteger As Integer
Private TotalDollarAmountDepositsDecimal, TotalDollarAmountChecksDecimal, AccountBalanceDecimal, AmountDecimal, TotalAmountServiceChargeDecimal As Decimal
'Declare module-level constants.
Const SERVICE_CHARGE_Decimal As Decimal = 10D
Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
'Terminate the project.
Me.Close()
End Sub
Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click
'Prints the form.
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
PrintForm1.Print()
End Sub
Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
'Calculate the balance by adding deposits, and subtracting service charges and checks.
Dim AmountDecimal As Decimal
Try
If Decimal.Parse(EnterAmountTextBox.Text) > 0 Then
'assigns the variable
AmountDecimal = Decimal.Parse(EnterAmountTextBox.Text)
'checks to see which radio button is checked and performs calculations.
If DepositRadioButton.Checked Then
AccountBalanceDecimal += AmountDecimal
TotalDollarAmountDepositsDecimal += AmountDecimal
TotalNumberDepositsCountInteger += 1
ElseIf CheckRadioButton.Checked Then
'checks to see if balance is greater than the amount entered.
If AccountBalanceDecimal >= AmountDecimal Then
AccountBalanceDecimal -= AmountDecimal
TotalNumberChecksCountInteger += 1
TotalDollarAmountChecksDecimal += AmountDecimal
'If amount entetered is more than the balance, then give an error, and deduct $10.00 from balance.
Else
MessageBox.Show("Insufficient Funds")
AccountBalanceDecimal -= SERVICE_CHARGE_Decimal
TotalDollarAmountChecksDecimal += SERVICE_CHARGE_Decimal
TotalServiceChargeInteger += 1
End If
ElseIf ServiceChargeRadioButton.Checked Then
AccountBalanceDecimal -= AmountDecimal
TotalAmountServiceChargeDecimal += AmountDecimal
TotalServiceChargeInteger += 1
'If no radio button is selected thengive 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
AccountBalanceTextBox.Text = AccountBalanceDecimal.ToString("C")
'If numeric values are not entered, then give an error.
Else
MessageBox.Show("You cannot enter negative numbers into the ammount textbox." _
, "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Catch
MessageBox.Show("You must enter numbers into the ammount textbox", "Invalid Input" _
, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
'Clear the appropriate controls
AccountBalanceTextBox.Clear()
With EnterAmountTextBox
.Clear()
.Focus()
End With
DepositRadioButton.Checked = False
CheckRadioButton.Checked = False
ServiceChargeRadioButton.Checked = False
End Sub
Private Sub SummaryButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SummaryButton.Click
'Display Summary Information.
Dim MessageString As String
'Concatenate the message string
MessageString = "Total Deposits: " _
& TotalNumberDepositsCountInteger.ToString() _
& Environment.NewLine & Environment.NewLine _
& "Total Amount of Deposits: " & TotalDollarAmountDepositsDecimal.ToString("C") _
& Environment.NewLine & Environment.NewLine _
& "TotalChecks: " & TotalNumberChecksCountInteger.ToString() _
& Environment.NewLine & Environment.NewLine _
& "Total Amount of Checks: " & TotalDollarAmountChecksDecimal.ToString("C") _
& Environment.NewLine & Environment.NewLine _
& "Total Service Charges: " & TotalServiceChargeInteger.ToString() _
& Environment.NewLine & Environment.NewLine _
& "Total Amount of Service Charges: " & TotalAmountServiceChargeDecimal.ToString("C")
MessageBox.Show(MessageString, "Checking Account Summary", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
End Class
Last edited by admin : 08-Oct-2009 at 00:37.
Reason: Please insert your example VB codes between [VB] and [/VB] tags
|
|