‘************************************ Public Sub DataLength_Limit(obj As TextBox) ‘, MaxLen as Integer)
Dim iLenUnicode As Integer Dim i As Integer Dim MaxLen As Integer Dim sText As String Dim j As Integer j = obj.SelStart sText = obj.Text MaxLen = obj.MaxLength If sText = "" Or MaxLen = 0 Then Exit Sub End If iLenUnicode = Len(sText) For i = 1 To iLenUnicode If lstrlen(sText) > MaxLen Then iLenUnicode = iLenUnicode - 1 sText = Left(sText, iLenUnicode) Else Exit For End If Next i obj.Text = sText obj.SelStart = j End Sub ‘************************************
‘函數(shù)名: NumKeyPress() ‘參數(shù) : obj :需處理的TEXTBOX對(duì)象 ‘ Keyascii:需處理的ascii字符 ‘ IntPlaces:最大整數(shù)位 ‘ DecPlaces:最大小數(shù)位 ‘返回值: 數(shù)字字符 ‘ ‘說明 : 限制輸入非數(shù)字字符,,確保輸入的為允許有效數(shù)字 ‘************************************ Public Function NumKeyPress(obj As TextBox, KeyAscii As Integer, IntPlaces As Integer, DecPlaces As Integer) As Integer
Dim i As Integer Dim j As Integer Dim k As Integer Dim ilen As Integer NumKeyPress = KeyAscii
i = obj.SelStart
j = InStr(obj.Text, ".") k = obj.SelLength ilen = Len(obj.Text) If KeyAscii = vbKeyBack Then
If k = 0 Then If i = j Then If ilen - 1 > IntPlaces Then NumKeyPress = 0 End If End If Else If InStr(obj.SelText, ".") > 0 Then If ilen - k > IntPlaces Then NumKeyPress = 0 End If End If End If End If
If KeyAscii >= 33 Then If (KeyAscii < vbKey0 Or KeyAscii > vbKey9) And KeyAscii <> 46 Then NumKeyPress = 0 Else If KeyAscii = 46 Then If InStr(obj.Text, ".") > 0 Then NumKeyPress = 0 End If Else If j > 0 Then If i >= j And (ilen - j) >= DecPlaces Then NumKeyPress = 0 ElseIf i < j And j >= IntPlaces + 1 Then NumKeyPress = 0 End If Else If ilen >= IntPlaces Then NumKeyPress = 0 End If End If End If End If End If End Function
‘************************************ ‘函數(shù)名: NumKeyDown() ‘參數(shù) : obj :需處理的TEXTBOX對(duì)象 ‘ KeyCode:需處理的KeyCode字符 ‘ IntPlaces:最大整數(shù)位 ‘ DecPlaces:最大小數(shù)位 ‘返回值: 數(shù)字字符 ‘ ‘說明 : 限制輸入非數(shù)字字符,,確保輸入的為允許有效數(shù)字,,主要響應(yīng)“Delete”健 ‘************************************ Public Function NumKeyDown(obj As TextBox, KeyCode As Integer, IntPlaces As Integer, DecPlaces As Integer) As Integer
Dim i As Integer Dim j As Integer Dim k As Integer Dim ilen As Integer NumKeyDown = KeyCode
i = obj.SelStart
j = InStr(obj.Text, ".") k = obj.SelLength ilen = Len(obj.Text) If KeyCode = 46 Then
If k = 0 Then If i + 1 = j Then If ilen - 1 > IntPlaces Then NumKeyDown = 0 End If End If Else If InStr(obj.SelText, ".") > 0 Then If ilen - k > IntPlaces Then NumKeyDown = 0 End If End If End If End If
End Function ‘************************************ ‘函數(shù)名: pbCheckChar ‘參數(shù) : intKeyascii:需處理的Keyascii字符 ‘‘返回值: 數(shù)字字符 ‘ ‘說明 : 限制輸入字符,,確保輸入的為允許字符 ‘************************************ Public Function pbCheckChar(intKeyascii As Integer) As Integer
If intKeyascii = 37 Or intKeyascii = 34 Or intKeyascii = 39 Or intKeyascii = 63 Then pbCheckChar = 0 Else pbCheckChar = 1 End If End Function |
|