Visual Basic Code |
Private Sub Form_Load ( ) Text1.Tag = 0 Text1_LostFocus End Sub Private Sub Text1_GotFocus ( ) Text1.Text = Text1.Tag Text1.SelStart = 0 Text1.SelLength = Len ( Text1.Text ) End Sub Private Sub Text1_KeyPress ( KeyAscii As Integer ) If KeyAscii > = Asc ( "0" ) And KeyAscii < = Asc ( "9" ) Or KeyAscii = 8 Or KeyAscii = Asc ( "." ) Then If KeyAscii = Asc ( "." ) And InStr ( 1, Text1.Text, ".", vbTextCompare ) > 0 Then KeyAscii = 0 End If If Text1.SelStart > = Len ( Text1.Text ) - 2 And _ InStr ( 1, Text1.Text, ".", vbTextCompare ) > 0 And _ Len ( Text1.Text ) - InstrRev ( Text1.Text, ".", Len ( Text1.Text ) , vbTextCompare ) > = 2 And _ KeyAscii <> 8 Then KeyAscii = 0 End If Else KeyAscii = 0 End If End Sub Private Sub Text1_LostFocus ( ) Dim SaveNumer As Currency If IsNumeric ( Text1.Text ) = False Then SaveNumer = 0 Else SaveNumer = Format ( Text1.Text, "0.00" ) End If Text1.Tag = SaveNumer Text1.Text = Format ( SaveNumer, "¥0.00" ) End Sub |