请教一下论坛里的朋友,现在有一个text 然后控制它的输入字符长度不能超过50个
有什么办法吗?找过例子  呵呵小弟实在是他愚钝了。 麻烦大家了

解决方案 »

  1.   

    if len(text1.text)>50 then
         msgbox ""
         exit sub
    end if
      

  2.   

    除了 MaxLength = 50 外,保存前最好用个函数判断一下。因为50个中文字与50个英文字显然不是一样的,写入数据库时可能出现问题。
      

  3.   

    判断中英文混合字符的长度用下面代码:?lenb(strconv("abc",vbFromUnicode))
    3?lenb(strconv("abc测试",vbFromUnicode))
    7(一个汉字算两个英文字长)
      

  4.   

    判断中英文混合字符的长度用下面代码:?lenb(strconv("abc",vbFromUnicode))
    3?lenb(strconv("abc测试",vbFromUnicode))
    7(一个汉字算两个英文字长)
      

  5.   

    多谢大家拉。。
    不过有个方法似乎蛮复杂是用函数来写的 
    大家看看~
    Public Function pfunGetLen(StrText As String) As Integer
        Dim i As Integer
        Dim StrLen As Integer
            StrLen = 0
        For i = 1 To Len(StrText)
            If Asc(Mid(StrText, i, 1)) > 0 Then
               StrLen = StrLen + 1
            Else
               StrLen = StrLen + 2
            End If
        Next
        pfunGetLen = StrLen
    End FunctionPrivate Function funLengthControl(textBoxName As TextBox, KeyAscii As Integer) As Integer
        If pfunGetLen(Replace(textBoxName.Text, textBoxName.SelText, "") & Chr(KeyAscii)) > textBoxName.maxLength And KeyAscii <> 8 Then
            funLengthControl = 0
        Else
            If KeyAscii = vbKeyReturn And pfunGetLen(Replace(textBoxName.Text, textBoxName.SelText, "")) > textBoxName.maxLength - 2 Then
                funLengthControl = 0
            Else
                funLengthControl = KeyAscii
            End If
        End If
    End Function