Actually, overall, your logic is pretty good, and your syntax, while a bit verbose is also rather good.
To display your result, simply apply it to the acctBalanceTextBox:
acctBalanceTextBox.value = acctBalDecimal ' see line in pink below
Place this statement after the end if line... This will update the display with the updated value, regardless of what operation was performed. It;s that simple. You don;t have to "show" the result, just update the text box.
Minor notes in blue (really, your approach is good, these are just things to think about):
Public Class Form1 ' Use a more descriptive name
Private acctBalDecimal As Decimal ' This is fine, but within a class the default visibility is private. To make it non-private (public or friend) you have to be explicit, but you could use Dim here instead of private, safely.
' However, your naming is verbose even by VB's standards. It IS your choice, but AcctBal (no hungarian notation) or decAcctBalance are both easier to read than the fully type qualified extension you chose to use. As a rule try to use a variable name that captures the intention, but doesn't do too much more.
There are lots of arguments about whether Hungarian notation is still worthwhile. I won't get into those... but I will say typing out 'Decimal' is overkill.
' Overall, This is fine... However, are we happy with the idea that the balance starts out as zero?
Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
'Calculate the account balance
Dim currentBalDecimal, amtEnteredDecimal As Decimal ' This works the way you intend in .NET, but being explicit about each variable's type is still clearer: Dim x as type, y as type. Not a big deal.
With Me
Try ' Good job! Place your "stuff" in try bocks!
'convert input to numeric
amtEnteredDecimal = Decimal.Parse(.amountTextBox.Text)
' Nicely done using the .NET Parse methods of the data type class. There are a lot of ways to do this, but I really like this one. Note that THIS statement does all the work that requires the input to be numerical and semantically meaningful. Thus, if all you wanted was to test for numeric input you can end your try block here. There are other errors that can occur, though (not many in this simple an app, but there are a few).
If .depositRadioButton.Checked Then
' This works in any version of VB, but style guides prefer explicit comparisons, so use .depositRadioButton.Checked = True. Again, this is style only, and not a really big deal... but VB6 uses True = -1 and .NET uses True <> 0, while the value of True translates correctly between platforms.
.depositRadioButton.Checked = True
' This line is fully redundant with your test condition. Omit it.
.checkRadioButton.Checked = False
.serviceChargeRadioButton.Checked = False
' Do you intend that these two lines do what they do? That is, if the deposit button is checked, then clear the check and sc buttons, regardless of what their state is? If they are actually radio buttons, then only one can be checked, anyway. I suspect that the 3 lines of code above acccomplish exactly nothing.
acctBalDecimal = (currentBalDecimal + amtEnteredDecimal)
ElseIf .checkRadioButton.Checked Then
.depositRadioButton.Checked = False
.checkRadioButton.Checked = True
.serviceChargeRadioButton.Checked = False
' Again the 3 lines above seem to accomplish nothing
acctBalDecimal = (currentBalDecimal - amtEnteredDecimal)
ElseIf .serviceChargeRadioButton.Checked Then
.depositRadioButton.Checked = False
.checkRadioButton.Checked = False
.serviceChargeRadioButton.Checked = True
' Again the 3 lines above seem to accomplish nothing
acctBalDecimal = (currentBalDecimal - amtEnteredDecimal)
End If
' Good job thinking of the catch block!
Catch anyException As Exception ' use e or ex for the exception variable as a matter of style
MessageBox.Show("Nonnumeric Data.", "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
' Ah... but you HAVE NOT checked for non-numeric data... you have checked for ANY exception. so, if your computer memory overflows, instead of a stack overflow excception....... Still, this is okay for now.
End Try
.acctBalanceTextBox.value = acctBalDecimal ' ONLY CHANGE YOU NEED
End With
End Sub
Private Sub clearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearButton.Click
'clears the amount entered
' Yes, but it doesn't reset the selection.... if you intend that deposit is the default, it should set to that (an unset the others). If you intend there to be no default, it should set the group value to Null (set all radio buttons to unchecked.).
With Me
With .amountTextBox
.Clear()
.Focus()
End With
End With
End Sub
Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click
'Exit the program ' Well, yes, this time., but really you are simply closing the form
Me.Close()
End Sub
End Class
Here's my simpler version (warning : air code)
Public Class BalanceCalculator
Dim decActBal As Decimal
Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
'Calculate the account balance
Dim decCurrentBal As Decimal , decAmtEntered As Decimal
With Me
Try
'convert input to numeric
amtEnteredDecimal = Decimal.Parse(.amountTextBox.Text)
Catch anyException As Exception ' use e or ex for the exception variable as a matter of style
MessageBox.Show("Nonnumeric Data.", "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
' Insert code to test that value is not zero, or negative, here.
If .depositRadioButton.Checked Then
decActBal = (decCurrentBal + decAmtEntered )
ElseIf .checkRadioButton.Checked Then
decActBal = (decCurrentBal - decAmtEntered )
ElseIf .serviceChargeRadioButton.Checked Then
decActBal = (decCurrentBal - decAmtEntered )
End If
.acctBalanceTextBox.value = acctBalDecimal
End With
End Sub
<snip out other subroutines>
End Class
________________________________
From: helpwithvb%40yahoogroups.com">helpwithvb
yahoogroups.com on behalf of SLM139%40aol.com">SLM139
aol.com
Sent: Tue 10/2/2007 10:12 AM
To: helpwithvb%40yahoogroups.com">helpwithvb
yahoogroups.com
Subject: Re: [helpwithvb] Re:newbie
Public Class Form1
Private acctBalDecimal As Decimal