You should come across scenario where you need to validate value of a textbox and then do some calculation after someone enter value into a textbox and leave the field. Typically we will just LostFocus event and perform the two tasks in this event handler block.
In .net, you should split your code to Validating and Validated events. The following code is a sample.
Private Sub txtCubicCapacity_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtCubicCapacity.Validating
If txtCubicCapacity.Text.Length > 0 Then
If Not ValidateCubicCapacity(txtCubicCapacity.Text) Then
e.Cancel = True
End If
End If
End Sub
Private Sub txtCubicCapacity_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCubicCapacity.Validated
If txtCubicCapacity.Text.Length > 0 Then
txtVehicleClass.Text = GetVehicleClassByCubicCapacity(txtCubicCapacity.Text)
End If
End Sub
Public Function ValidateCubicCapacity(ByVal CubicCapacity As String) As Boolean
ValidateCubicCapacity = False
If Not IsNumeric(CubicCapacity) Then
MsgBox("Cubic Capacity must be in numeric.", MsgBoxStyle.Exclamation, "Validation")
Exit Function
End If
If Not Convert.ToInt32(CubicCapacity) > 0 Then
MsgBox("Cubic Capacity must be more than 0.", MsgBoxStyle.Exclamation, "Validation")
Exit Function
End If
ValidateCubicCapacity = True
End Function
The reason why you should use Validating event to do validation code is because this event expose e.Cancel property within the event handler so that if validation fails, you just need to set this property to false and exit the block. The textbox will acknowledge the validation failure and set focus back to textbox.
The reason that calculation code should be in Validated event instead of LostFocus is that Validated event is the event raised immediately after validated. This ensures that your code is executed only after proper validation is successfully done.
Friday, June 30, 2006
Thursday, June 22, 2006
Medical Problem vs. Economic Solution
Did any of you realize that food store out that is cutting down sugar input because of recent sugar shortage? Did you feel you teh tarik is less sweet even though you didn't ask for less sugar?
I felt it and I think this is great measures to help our country from suffering a diabetic illness. As the sugar intake is reduce, our body has less sugar spite (attack). Thus, cause less disturbance to you body.
Sometime, the medical problem can be solved by an economic solution... :)
I felt it and I think this is great measures to help our country from suffering a diabetic illness. As the sugar intake is reduce, our body has less sugar spite (attack). Thus, cause less disturbance to you body.
Sometime, the medical problem can be solved by an economic solution... :)
Tuesday, June 20, 2006
Memory leek in VS2005 VB Compiler
Some of you may be experiencing slowness in VS2005 IDE. It may be cause by a reported memory leek in VB Compiler when opening large vb projects. There is a hotfix where you can install to see if it will improve the performance.
I have experienced this problem on my Pentium D 1GB box. I develop enterprise application that usually spans across many projects. Before apply the hotfix, it took me more than 30 seconds to do a local compilation. The memory utilization on devenv.exe will shoot up to 800MB while maintaing 400MB during development.
Another strange thing is VS2005 IDE will automatically save recovery information from time to time. It took more than 20 seconds to do each save!! It is driving me nuts.
After applying the hotfix, devenv.exe is now maximum 240MB and I don't have to wait while developing anymore.
Here is the KB Microsoft published about the hotfix. Aparently, you need to call the support centre in order to get the email to download the hotfix.
If any of you have problem getting the hotfix, just drop me a comment. I can email it to you.
I have experienced this problem on my Pentium D 1GB box. I develop enterprise application that usually spans across many projects. Before apply the hotfix, it took me more than 30 seconds to do a local compilation. The memory utilization on devenv.exe will shoot up to 800MB while maintaing 400MB during development.
Another strange thing is VS2005 IDE will automatically save recovery information from time to time. It took more than 20 seconds to do each save!! It is driving me nuts.
After applying the hotfix, devenv.exe is now maximum 240MB and I don't have to wait while developing anymore.
Here is the KB Microsoft published about the hotfix. Aparently, you need to call the support centre in order to get the email to download the hotfix.
If any of you have problem getting the hotfix, just drop me a comment. I can email it to you.
Monday, June 19, 2006
Aussies Rules!!
watched Aussies vs Brazil game yesterday. It feels great just to see Brazil struggled to score. :)
Subscribe to:
Posts (Atom)