1,451
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Private Sub Form_Load()
Text1.MaxLength = 4
Text1 = ""
End Sub
Private Sub Text1_Change()
Dim strS As String
strS = Text1
If Len(Text1) > 2 Then
If CInt(Mid(strS, 3, Len(Text1) - 2)) > 12 Then
Text1.SelStart = 2
Text1.SelLength = 2
End If
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
Option Explicit
Private Sub Form_Load()
Text1.MaxLength = 4
Text1 = ""
End Sub
Private Sub Text1_Change()
Dim strS As String
strS = Text1
If Len(Text1) > 2 Then
If CInt(Mid(strS, 3, Len(Text1) - 2)) > 30 Then
Text1.SelStart = 2
Text1.SelLength = 2
End If
Else
If CInt(Left(strS, 2)) > 12 Then
Text1.SelStart = 0
Text1.SelLength = 2
End If
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Me.TextBox1.MaxLength = 4
If Char.IsNumber(e.KeyChar) = False Then
If Char.IsControl(e.KeyChar) = True Then
e.Handled = False
Else
e.Handled = True
End If
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If Me.TextBox1.Text = "00" Then
Me.TextBox1.Text = ""
End If
End Sub
Private Sub Text1_Change()
If Not IsNumeric(Text1.Text) Then
MsgBox "?"
Text1.Text = ""
Text1.SetFocus
End If
If Len(Text1.Text) > 4 Then
MsgBox "?"
Text1.Text = Left(Text1.Text, 4)
End If
If Mid(Text1.Text, 3, 2) > 12 Then
MsgBox "?"
Text1.Text = Left(Text1.Text, 2)
End If
End Sub
Private Sub Text1_LostFocus()
b = Left(Text1.Text, 2)
If Len(Trim(Text1.Text)) = 4 And IsNumeric(Text1.Text) And CInt(b) <> 0 And CInt(b) < 13 Then
MsgBox "ok"
Else
MsgBox "no"
End If
End Sub