控制输入问题给分帖2

a040liutao 2005-05-26 09:58:39
原贴
http://community.csdn.net/Expert/topic/4036/4036412.xml?temp=.8441736

解决问题的进来领分!
...全文
89 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hsghxm 2005-05-26
  • 打赏
  • 举报
回复
'呵呵,来领分的:)
Option Explicit



Private Sub Text1_KeyPress(KeyAscii As Integer)

Select Case KeyAscii
Case 48 To 57
Case 46
Case 8
Case Else
KeyAscii = 0
End Select
End Sub

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Dim s As String, SearchChar As String
Dim i As Integer
s = Text1.Text
Dim x As Integer
SearchChar = "."
x = InStr(1, s, SearchChar, 1)
If x = 0 Then
If Len(s) > 2 Then
Text1.Text = Mid(s, 1, 2)
End If

ElseIf x <= 3 Then
If x < Len(s) Then
Text1.Text = Left(Text1.Text, x - 1) + "." + Right(Text1.Text, Len(Text1.Text) - x)
End If
If Len(Right(s, Len(s) - x)) > 2 Then
Text1.Text = Left(Text1.Text, x - 1) + "." + Mid(Text1.Text, x + 1, 2)
End If
ElseIf x > 3 Then
Text1.Text = Mid(s, 1, 2)
End If
End Sub
tmran 2005-05-26
  • 打赏
  • 举报
回复

Option Explicit

Private Sub Text1_Change()

Dim I, L As Long

L = InStr(1, Text1.Text, ".")
If L > 1 And L + 2 < Len(Text1.Text) Then
Text1.Text = Left(Text1.Text, L + 2)
End If
If Text1.Text <> "" Then
If (Asc(Right(Text1.Text, 1)) < 48 Or Asc(Right(Text1.Text, 1)) > 57) And Asc(Right(Text1.Text, 1)) <> 46 Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End If
End If

Text1.SetFocus
SendKeys "{End}"

End Sub
DooDu 2005-05-26
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/4036/4036420.xml?temp=2.685183E-02
答案已经有了
51365133 2005-05-26
  • 打赏
  • 举报
回复
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (Len(Text1.Text) = 0) And (KeyAscii = 46) Then KeyAscii = 0
If (KeyAscii = 46) And (InStr(Text1.Text, ".")) Then KeyAscii = 0
If (KeyAscii < 48 Or KeyAscii > 57) And (KeyAscii <> 46) Then KeyAscii = 0
If (InStr(Text1.Text, ".")) Then
If (Len(Text1.Text) - InStr(Text1.Text, ".")) >= 2 Then KeyAscii = 0
Else
If (Len(Text1.Text) = 2) And (KeyAscii <> 46) Then KeyAscii = 0
End If
End Sub

一个都不能少

741

社区成员

发帖
与我相关
我的任务
社区描述
VB 版八卦、闲侃,联络感情地盘,禁广告帖、作业帖
社区管理员
  • 非技术类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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