TextBox 限制输入长度
来源:www.hosp.ncku.edu.tw/~cww/oldguy/oldguy.htm
寄件者: Annie Chiu
在VB中使用text 的maxlength 屬性,我的資料欄位長度為10, 如何控制text 只能輸入10個英文字, 或5個中文字呢?
老怪答:
用 textbox.maxlength 的屬性,它還是會把兩 byte 的中文算一個字,你參考下面的程式碼,或許能達成你的目標。
Private Sub Text1_Change()
Static OldString As String
If LenB(StrConv(Text1.Text, vbFromUnicode)) > 10 Then
Text1.Text = OldString
End If
OldString = Text1.Text
End Sub
Access软件网交流QQ群(群号:198465573) |