VB开发——如何实现只允许输入汉字的文本框
Private Sub SrcTxt_Change()
Static SStr As String
Dim i As Integer
TotalNum = 0
L = Len(SrcTxt.Text)
For i = 1 To L
tmpStr = StrConv(Mid$(SrcTxt.Text, i, 1), vbWide)
If Asc(Mid$(SrcTxt.Text, i, 1)) < 0 Then
TotalNum = TotalNum + 1
SStr = SrcTxt.Text
Else
MsgBox "写入的不是汉字!"
SrcTxt.Text = Left(SrcTxt.Text, Len(SrcTxt.Text) - 1)
Exit Sub
End If
Next i
LblNum.Caption = Str$(TotalNum) + "个汉字"
End Sub
使用了change属性,可是实时的判断。
还顺便发现了几篇文章和资料,一起摘录过来了
关于VB操作Excel的:
http://blog.csdn.net/rainsnow/archive/2005/01/04/239385.aspx
http://blog.csdn.net/evanju/archive/2005/02/16/289557.aspx
http://blog.csdn.net/lwjvince/archive/2006/03/10/620942.aspx