It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

Using the Function procedure in Visual Basic Express

Moderator: dafunkymunky

Using the Function procedure in Visual Basic Express

Postby butl3111 on Fri Apr 01, 2011 2:26 pm

I am doing a program which I used buttons for the Calculate, Clear, Print, Exit, but decided to use Menu Strip and want to use the Function procedure for some of my code, but I am not understanding how to do this. I want to use function procedures for processing my deposits, checks, and service charges. Here is the code I have thus far:
[Public Class CheckingAccountForm
'Declare Module variables.

Private DepositCounterInteger, CheckCounterInteger, SerChargeInteger As Integer
Const SERVICE_CHARGE_Decimal As Decimal = 10D
Private BalDecimal, TotalServChgDecimal, TotalDepositDecimal, TotalCheckDecimal As Decimal

'Declare the module level variables for summary information.
Private MessageString As String
Private TotalNumberCheckCountInteger, TotalDepositCountInteger As Integer

Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
'Close the program

Me.Close()

End Sub

Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click


'Declare the variables.

Dim AmtTransDecimal As Decimal
Dim MessageString As String

If DepositRadioButton.Checked Or CheckRadioButton.Checked Or
ServiceChargeRadioButton.Checked Then

Try 'Calculate to find the Deposit - Check - Service Chg for Balance

AmtTransDecimal = Decimal.Parse(AmtofTransTextBox.Text)

If DepositRadioButton.Checked = True Then
BalDecimal += AmtTransDecimal
DepositCounterInteger += 1
TotalDepositDecimal += AmtTransDecimal

ElseIf CheckRadioButton.Checked = True Then
If AmtTransDecimal < BalDecimal Then
BalDecimal -= AmtTransDecimal
CheckCounterInteger += 1
TotalCheckDecimal += AmtTransDecimal

Else
MessageString = "Insufficient Funds:"
MessageBox.Show(MessageString, "Service Charge")
BalDecimal -= SERVICE_CHARGE_Decimal
SerChargeInteger += 1
TotalServChgDecimal += SERVICE_CHARGE_Decimal
End If

NewBalanceTextBox.Text = BalDecimal.ToString("C")
DepositCounterInteger += 1


ElseIf ServiceChargeRadioButton.Checked Then

BalDecimal -= AmtTransDecimal
SerChargeInteger += 1
TotalServChgDecimal += AmtTransDecimal
End If


'Display account balance.
NewBalanceTextBox.Text = BalDecimal.ToString("C")


Catch AmtTransException As FormatException
MessageBox.Show("Please enter only numeric data.",
"Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
With NewBalanceTextBox
.Focus()
.SelectAll()

End With

Catch AnyException As Exception
MessageBox.Show("Error: " & AnyException.Message)
End Try
Else
MessageBox.Show("Please choose deposit, check or service charge", "Entry is needed.")

End If

End Sub

Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
' Clear the transactions.
With AmtofTransTextBox
.Clear()
.Focus()

End With


End Sub

Private Sub SummaryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SummaryToolStripMenuItem.Click
TotalDepositCountInteger += DepositCounterInteger
TotalNumberCheckCountInteger += CheckCounterInteger
'Display the Summary Messages.

MessageString = "Number of Deposits: " & TotalDepositCountInteger.ToString() &
Environment.NewLine & "Total Deposit Amount: " & TotalDepositDecimal.ToString("C") &
Environment.NewLine & "Number of Checks: " & TotalNumberCheckCountInteger.ToString() &
Environment.NewLine & "Total Check Amount: " & TotalCheckDecimal.ToString("C") &
Environment.NewLine & "Service Charges: " & TotalServChgDecimal.ToString("C")

'Display the message box
MessageBox.Show(MessageString, "Your Account Summary", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub

Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
'Print the form to preview.

PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
PrintForm1.Print()
End Sub

Private Function Balance(ByVal TotalDepositDecimal As Decimal) As Decimal
Dim AmtTransDecimal As Decimal

' Add the deposit, checks, and service charges to the balance.
AmtTransDecimal = Decimal.Parse(AmtofTransTextBox.Text)

If DepositRadioButton.Checked = True Then

BalDecimal += AmtTransDecimal
' DepositCounterInteger += 1
' Return TotalDepositDecimal += AmtTransDecimal

End If
End Function
End Classe][/code]
I just need someone to explain in a simple way how to use the Function procedure.
Thanks
butl3111
 
Posts: 1
Joined: Fri Apr 01, 2011 2:16 pm

Who is online

Users browsing this forum: No registered users and 4 guests