# 参考这个程式吧！

Posted by 刘柏泛 on October 20, 1997 at 00:21:18:

In Reply to: Re: Text Control posted by 小贤 on October 20, 1997 at 00:02:27:

:
: : vb6 和 vb6 的TextBox的长度算法是一样的，要看你是使用
: 我主要是要问!
: vb6 和 vb6 的Text Control 的MaxLength 不一样!

Private Sub Text1_KeyPress(KeyAscii As Integer)
'Text1.MaxLength 要设长度（中文2个Byte，英文1个Byte）
Dim J(1) As Integer, Temp As Integer
J(0) = 0
For Temp = 1 To Len(Text1.Text)
J(1) = Asc(Mid(Text1.Text, Temp, 1))
J(0) = J(0) + IIf(J(1) >= 0 And J(1) 8 And KeyAscii 13 Then
Temp = IIf(KeyAscii 128, 2, 1)
If J(0) + Temp > Text1.MaxLength Then KeyAscii = 0
ElseIf KeyAscii = 13 Then
KeyAscii = 0
'保留给按 Enter 键时使用
'例如 Text2.SetFocus
End If

End Sub

Follow Ups:

- Re: 参考这个程式吧！ 小贤 02:58:26 10/20/97 (1)
  - 想是死心吧！但是.... 小吴 05:04:31 10/20/97 (0)