GAAP conformity. Better way of doing this?
Hi all,
I am making sure user input meets specific requirement to adhere to GAAP (Generally Acceptable Accounting Principals). I have coded something that works; however, I am wondering if there is a better way of doing this? In short, I have a MaskedTextBox that has a mask of 9-9999-9999. The five different GL account groups have specific guidelines to adhere to GAAP. I am working on Asset accounts right now. All account numbers based on GAAP start with the number one. I want to make sure this is adhered to in my app and if not, a messagebox comes up and then the first character is changed accordingly. Of course, this is working 1000%, but curious to see if there is a better way of doing this.
Code:
Private Sub AccountNumberAsset_LostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles AccountNumberAsset.LostFocus
With AccountNumberAsset
.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals
Dim TheInput As String = .Text
Dim TheChar As Char = TheInput.Substring(0, 1)
If Not TheChar.ToString.Equals("1") Then
If MessageBox.Show("Asset account numbers follow GAAP within " & My.Application.Info.ProductName & ". The first character has been changed to the number 1 to meet the GAAP standards.", _
"Invalid Account Number Start", _
MessageBoxButtons.OK, _
MessageBoxIcon.Exclamation, _
MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.OK Then
.Focus()
TheInput.Replace(TheChar, "1")
End If
End If
End With
Re: GAAP conformity. Better way of doing this?
Firstly, as the documentation clearly states, you should not be handling the LostFocus event. If you want to be notified when a control loses focus then, as the documentation states, you handle the Leave event. That's not what you want though, because you don't want the control to lose focus if its contents is not valid. For that, you handle the Validating event. If validation fails then you set e.Cancel to True and the focus never leaves that control.
Also, if you want to know whether the first character in a String is not something specific then you would more efficiently do it like this:
Code:
If myString(0) <> "1"c Then
Re: GAAP conformity. Better way of doing this?
If the first digit must be a 1 in the first place... why let them enter it? I'd put a label with "1-" in it, put it immediately to the left of the textbox, then set the format to "9999-9999" ... since it's clearly an asset account (judging by the name) it's going to be "1-" no matter what... so why have the hassle of letting the user muck it up? Just give them the parts they can change.
-tg
Re: GAAP conformity. Better way of doing this?
Quote:
Originally Posted by
techgnome
If the first digit must be a 1 in the first place... why let them enter it? I'd put a label with "1-" in it, put it immediately to the left of the textbox, then set the format to "9999-9999" ... since it's clearly an asset account (judging by the name) it's going to be "1-" no matter what... so why have the hassle of letting the user muck it up? Just give them the parts they can change.
-tg
I was thinking about that as I was going through it and this is what I decided to do. Sometimes I over think things and make them more complicated than they need to be.