怎么限制文本框的数据格式?

vfp_system 2003-07-15 09:13:20
怎么限制文本框的数据格式?例如:我要用户在文本框当中只能按下面的格式输入,
四位数代表年,二位代表月,二位代表日,三者之间用点隔开,但这个点要显示在文本框当中,而且不能删除或改变。
...全文
16 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
rainstormmaster 2003-07-15
  • 打赏
  • 举报
回复
textbox的实现方法,建议使用MaskEdBox:

Private Sub Form_Load()
Text1.Text = ""
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim s As String
s = Text1.Text
Dim i As Long
i = Len(s)
If i >= Len("####.##.##") Then
KeyAscii = 0
Exit Sub
Else
If KeyAscii <> 8 Then '如果按下的不是退格键
Select Case i
Case 0
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Exit Sub
End If
Case 1
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Exit Sub
End If
Case 2
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Exit Sub
End If
Case 3
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Exit Sub
End If
Case 4
If KeyAscii <> 46 Then
KeyAscii = 0
Exit Sub
End If
Case 5
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Exit Sub
End If
Case 6
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Exit Sub
End If
Case 7
If KeyAscii <> 46 Then
KeyAscii = 0
Exit Sub
End If
Case 8
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Exit Sub
End If
Case 9
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Exit Sub
End If
End Select
End If
End If
End Sub

goodname008 2003-07-15
  • 打赏
  • 举报
回复
使用VB6企业版中的MaskEdBox控件,将其Mask属性设为####.##.##

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧