Private Sub vsGrid1_KeyPressEdit(ByVal Row As Long, ByVal Col As Long, KeyAscii As Integer) Select Case vsGrid1.ColDataType(Col)
Case 6, 14
If KeyAscii < vbKey0 Or KeyAscii > vbKey9 Then
Select Case KeyAscii
Case 8 '退格键
KeyAscii = 8
Case 46 '删除
If InStr(vsGrid1.TextMatrix(Row, Col), ".") = 0 Then
KeyAscii = 46
Else
KeyAscii = 0
End If
Case Else
KeyAscii = 0
End Select
End If
End Select
End Sub代码如上,但如果我这次输入的是3.3.3.3,还是能录入的,如果单元格中的内容是3.3,再录入.就无法录入了,连续的录入这段代码就没用了,还是可以录入多个小数点的,各位有什么好的解决方法?
Case 6, 14
If KeyAscii < vbKey0 Or KeyAscii > vbKey9 Then
Select Case KeyAscii
Case 8 '退格键
KeyAscii = 8
Case 46 '删除
If InStr(vsGrid1.TextMatrix(Row, Col), ".") = 0 Then
KeyAscii = 46
Else
KeyAscii = 0
End If
Case Else
KeyAscii = 0
End Select
End If
End Select
End Sub代码如上,但如果我这次输入的是3.3.3.3,还是能录入的,如果单元格中的内容是3.3,再录入.就无法录入了,连续的录入这段代码就没用了,还是可以录入多个小数点的,各位有什么好的解决方法?
Private Sub fg_KeyPressEdit(ByVal Row As Long, ByVal Col As Long, KeyAscii As Integer)
Dim Numbers1 As String '允许输入的字符
Dim Numbers2 As String
strNumbers1 = "1234567890 " + Chr(8) + Chr(46)
strNumbers2 = "1234567890 " + Chr(8) If InStr(strNumbers1, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
If InStr(strNumbers2, Chr(KeyAscii)) = 0 And InStr(fg.EditText, ".") <> 0 Then
KeyAscii = 0
End If
End Sub