List Info

Thread: Re: Re:newbie




Re: Re:newbie
country flaguser name
United States
2007-10-02 10:12:27

To all,
 
I definitely am not asking you to do my homework. I am 50 and am going to school to learn something I am interested in, I am not trying to waste my time or money to just get by in the class.
 
I am stuck on how to set the if/then statement up to add/subtract the amtEntered from the acctBalance and show in the acctBalanceTextBox. Here is what I have so far.
 
Public Class Form1
    'Project:       Checking Account
  ;  'Programmer:    Sherry Mantooth
    'Date:      ;    9/30/07
  ;  'Description:   This project will compute your checking account balance.
 
    'Dimension module-level variable
    Private acctBalDecimal As Decimal
 

    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
 
  ;      With Me
 ;           Try
          ;      'convert input to numeric
  ;           ;   amtEnteredDecimal = Decimal.Parse(.amountTextBox.Text)
 
          ;      If .depositRadioButton.Checked Then
        ;           ; .depositRadioButton.Checked = True
        ;           ; .checkRadioButton.Checked = False
      ;           ;   .serviceChargeRadioButton.Checked = False
      ;           ;   acctBalDecimal = (currentBalDecimal + amtEnteredDecimal)
  ;           ;   ElseIf .checkRadioButton.Checked Then
        ;           ; .depositRadioButton.Checked = False
      ;           ;   .checkRadioButton.Checked = True
        ;           ; .serviceChargeRadioButton.Checked = False
      ;           ;   acctBalDecimal = (currentBalDecimal - amtEnteredDecimal)
  ;           ;   ElseIf .serviceChargeRadioButton.Checked Then
        ;           ; .depositRadioButton.Checked = False
      ;           ;   .checkRadioButton.Checked = False
      ;           ;   .serviceChargeRadioButton.Checked = True
        ;           ; acctBalDecimal = (currentBalDecimal - amtEnteredDecimal)
 
  ;           ;   End If
 
 ;           Catch anyException As Exception
         ;       MessageBox.Show("Nonnumeric Data.", "Error", _
   ;           ;  MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
 

  ;          End Try
        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
      ;  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
  ;      Me.Close()
    End Sub
End Class




See what's new at AOL.com and Make AOL Your Homepage.

__._,_.___
.

__,_._,___
RE: Re:newbie
country flaguser name
United States
2007-10-02 14:07:56

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(&quot;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(&quot;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">helpwithvbyahoogroups.com on behalf of SLM139%40aol.com">SLM139aol.com
Sent: Tue 10/2/2007 10:12 AM
To: helpwithvb%40yahoogroups.com">helpwithvbyahoogroups.com
Subject: Re: [helpwithvb] Re:newbie

Public Class Form1
Private acctBalDecimal As Decimal


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

With Me
Try
'convert input to numeric
amtEnteredDecimal = Decimal.Parse(.amountTextBox.Text)

If .depositRadioButton.Checked Then
.depositRadioButton.Checked = True
.checkRadioButton.Checked = False
.serviceChargeRadioButton.Checked = False
acctBalDecimal = (currentBalDecimal + amtEnteredDecimal)
ElseIf .checkRadioButton.Checked Then
.depositRadioButton.Checked = False
.checkRadioButton.Checked = True
.serviceChargeRadioButton.Checked = False
acctBalDecimal = (currentBalDecimal - amtEnteredDecimal)
ElseIf .serviceChargeRadioButton.Checked Then
.depositRadioButton.Checked = False
.checkRadioButton.Checked = False
.serviceChargeRadioButton.Checked = True
acctBalDecimal = (currentBalDecimal - amtEnteredDecimal)

End If

Catch anyException As Exception
MessageBox.Show(&quot;Nonnumeric Data.";, "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)


End Try
.acctBalanceTextBox.value = acctBalDecimal
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
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
Me.Close()
End Sub
End Class

.


__._,_.___
.

__,_._,___
  
Re: Re:newbie
country flaguser name
United States
2007-10-02 23:40:03

Hi SML139...If you want it, I have a sample checkbook program that may help you in logic and tips on your project. It is in VB6 and is for learning only. The code is a lot of bits that others who have helped me in the past and although I do not know all the names, I give any who see their work credit in this sample. Oh! by the way at 50 is still young so, ;keep up the learning and doing. I just passed 70 and hopefully I can keep learning from this group as I have in the past.
Bob usewillowverizon.net">usewillowverizon.net
 
----- Original Message -----
Sent: Tuesday, October 02, 2007 8:12 AM
Subject: Re: [helpwithvb] Re:newbie

To all,
 
I definitely am not asking you to do my homework. I am 50 and am going to school to learn something I am interested in, I am not trying to waste my time or money to just get by in the class.
 
I am stuck on how to set the if/then statement up to add/subtract the amtEntered from the acctBalance and show in the acctBalanceTextBox. Here is what I have so far.
 
Public Class Form1
&nbsp; &nbsp; 'Project:&nbsp;   ; &nbsp; Checking Account
&nbsp; &nbsp; 'Programmer: &nbsp;  Sherry Mantooth
&nbsp;   'Date:&nbsp; &nbsp; &nbsp; &nbsp;   9/30/07
&nbsp; &nbsp; 'Description: &nbsp; This project will compute your checking account balance.
 
 &nbsp;  'Dimension module-level variable
&nbsp;   Private acctBalDecimal As Decimal
 

 &nbsp;  Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
 &nbsp; &nbsp; &nbsp;  'Calculate the account balance
&nbsp; &nbsp;   ;  Dim currentBalDecimal, amtEnteredDecimal As Decimal
 
 &nbsp; &nbsp; &nbsp;  With Me
 &nbsp;   ; &nbsp; &nbsp; &nbsp; Try
   ; &nbsp; &nbsp; &nbsp; &nbsp;   ;  'convert input to numeric
&nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  amtEnteredDecimal = Decimal.Parse(.amountTextBox.Text)
 
 &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; If .depositRadioButton.Checked Then
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp;  .depositRadioButton.Checked = True
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp;  .checkRadioButton.Checked = False
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  .serviceChargeRadioButton.Checked = False
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  acctBalDecimal = (currentBalDecimal + amtEnteredDecimal)
&nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  ElseIf .checkRadioButton.Checked Then
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp;  .depositRadioButton.Checked = False
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  .checkRadioButton.Checked = True
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp;  .serviceChargeRadioButton.Checked = False
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  acctBalDecimal = (currentBalDecimal - amtEnteredDecimal)
&nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  ElseIf .serviceChargeRadioButton.Checked Then
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp;  .depositRadioButton.Checked = False
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  .checkRadioButton.Checked = False
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  .serviceChargeRadioButton.Checked = True
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp;  acctBalDecimal = (currentBalDecimal - amtEnteredDecimal)
 
 &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; End If
 
 &nbsp; &nbsp; &nbsp;   ; &nbsp; Catch anyException As Exception
  ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; MessageBox.Show("Nonnumeric Data.", "Error", _
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp; MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
 

 &nbsp; &nbsp;   ; &nbsp; &nbsp; End Try
   ; &nbsp; &nbsp; End With
 
 &nbsp;  End Sub
 
 &nbsp;  Private Sub clearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearButton.Click
&nbsp; &nbsp;   ;  'clears the amount entered
&nbsp; &nbsp;   ;  With Me
 &nbsp;   ; &nbsp; &nbsp; &nbsp; With .amountTextBox
   ; &nbsp; &nbsp; &nbsp; &nbsp;   ;  .Clear()
&nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; .Focus()
&nbsp;   ; &nbsp; &nbsp; &nbsp;  End With
 ; &nbsp; &nbsp; &nbsp; End With
 ; &nbsp; End Sub
 
 &nbsp;  Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click
&nbsp; &nbsp; &nbsp; &nbsp; 'Exit the program
&nbsp; &nbsp;   ;  Me.Close()
 &nbsp;  End Sub
End Class




See what's new at AOL.com and Make AOL Your Homepage.

__._,_.___
.

__,_._,___
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )