Question:
Can someone help with this Visual Basic pseudocode?
Kal-El2K8
2011-07-13 17:30:44 UTC
I put the main portions of a pseudocode for a project that I did recently for my Visual Basic class. For some reason when I click the summary tool strip menu item it only shows the summary for the last transaction. I need it to show the summary for all the transactions that the user enters up to that point. Can anyone see what I'm doing wrong?

Private Sub SummaryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SummaryToolStripMenuItem.Click
'Declare Variables
Const SERVICE_CHARGE As Decimal = 10.0
Dim TotalDeposits, TotalChecks, AccountBalance As Decimal
Dim Number_Of_Deposits, Number_Of_Checks As Integer
Dim MessageString As String

'Calculate
AccountBalance = Decimal.Parse(EnterAmountTextBox.Text)

If DepositRadioButton.Checked Then
TotalDeposits = (TotalDeposits + AccountBalance)
Number_Of_Deposits = (Number_Of_Deposits + 1)
ElseIf CheckRadioButton.Checked And AccountBalance > 0 Then
TotalChecks = (TotalChecks + AccountBalance)
Number_Of_Checks = (Number_Of_Checks + 1)
End If

If CheckRadioButton.Checked And AccountBalance < 0 Then
AccountBalance = (AccountBalance - SERVICE_CHARGE)
End If

MessageString = "Total Number of Deposits: " _
& Number_Of_Deposits.ToString() _
& Environment.NewLine & Environment.NewLine _
& "Total Amount of Deposits: " _
& TotalDeposits.ToString("c") _
& Environment.NewLine & Environment.NewLine _
& "Total Number of Checks: " _
& Number_Of_Checks.ToString() _
& Environment.NewLine & Environment.NewLine _
& "Total Amount of Checks: " _
& TotalChecks.ToString("c")
MessageBox.Show(MessageString, "Account Summary", MessageBoxButtons.OK, MessageBoxIcon.None)



End Sub

Private Sub TransactionToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TransactionToolStripMenuItem.Click
'Declare Variables
Dim EnterAmount, AccountBalance As Decimal
Const SERVICE_CHARGE As Decimal = 10.0
'Calculate
EnterAmount = Decimal.Parse(EnterAmountTextBox.Text)

'Determine if the amount entered is to be added or subtracted
If DepositRadioButton.Checked Then
AccountBalanceTextBox.Text = (AccountBalance + EnterAmount).ToString("c")
ElseIf CheckRadioButton.Checked Then
AccountBalanceTextBox.Text = (AccountBalance - EnterAmount).ToString("c")
ElseIf ServiceChargeRadioButton.Checked Then
AccountBalanceTextBox.Text = (AccountBalance - SERVICE_CHARGE).ToString("c")
End If

'Display a message box if there are insufficient funds in the account
If CheckRadioButton.Checked = True Then
If EnterAmount > AccountBalance Then
MessageBox.Show("Insufficient Funds: $10.00 Service Charge!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
AccountBalanceTextBox.Text = (AccountBalance - SERVICE_CHARGE).ToString("c")
End If
End If

'Display a message box if the amount entered is a negative number
If EnterAmount < 0 Then
MessageBox.Show("Please enter an amount greater than zero!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End Sub
Three answers:
Gardner
2011-07-13 17:50:27 UTC
Private Sub SummaryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SummaryToolStripMenuItem.Click

'Declare Variables

Const SERVICE_CHARGE As Decimal = 10.0

Dim TotalDeposits, TotalChecks, AccountBalance As Decimal



On that last line you define TotalDeposits with no value assigned to it. So each time you run this Sub the value is reset to 0.



Then you say :

TotalDeposits = (TotalDeposits + AccountBalance)



TotalDeposits will always be 0 before this line executes.



You repeated that same error with a great deal of the code you posted. The objects are going out of scope and losing their values.
?
2017-01-01 12:51:41 UTC
think of of pseudocode simply by fact the particular logic of ways your software is going to artwork, step by step, with no need slowed down in the syntax of a particular programming language. to assist your self suited pseudocode, ask your self those questions and write down the solutions. it is going to help you get began writing the pseudocode logic. What inputs from the person do i could desire to get? What am I going to do with the inputs when I get them? What am I going to do with the consequence? Do i could desire to repeat the approach in any respect? How am I going to reveal the consequence(s) to the person?
2016-11-30 19:59:23 UTC
think of of pseudocode using fact the particular logic of how your application is going to paintings, step by step, without getting slowed down interior the syntax of a particular programming language. to help your self perfect pseudocode, ask your self those questions and write down the solutions. it is going that may be useful you start writing the pseudocode logic. What inputs from the consumer do i might desire to get? What am I going to do with the inputs when I get them? What am I going to do with the result? Do i might desire to repeat the approach in any respect? How am I going to exhibit the result(s) to the consumer?


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...