2,462
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Private Sub Form_Load()
Text1.MaxLength = 8
Text1 = ""
End Sub
Private Sub Text1_Change()
If Len(Text1) = 2 Then Text1 = Text1 & ","
If Len(Text1) = 5 Then Text1 = Text1 & "."
Text1.SelStart = Len(Text1)
End Sub
Private Sub Text1_Click()
Text1.SelStart = Len(Text1)
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Then
ElseIf KeyAscii = Asc(vbCr) Or KeyAscii = Asc(vbTab) Then
ElseIf KeyAscii = 8 Then
If Len(Text1) = 3 Or Len(Text1) = 6 Then
Text1 = Left(Text1, Len(Text1) - 2)
KeyAscii = 0
End If
Else
KeyAscii = 0
End If
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 46 Or KeyCode = 110 Then
Text1 = ""
End If
End Sub
Private Sub Text1_Validate(Cancel As Boolean)
If LenB(Text1.Text) <> 0 Then
If Not Text1.Text Like "##,##.##" Then
MsgBox "输入不合法。", vbExclamation
Cancel = True
End If
End If
End Sub