请问各们大虾们,关于Text的一个问题

smallbeggar2002 2003-08-22 10:28:22
我的Text1里只想输入8个普通字符
然后自动跳到text2中而text2里也只能输入8个普通字符,然后跳到text3............
一直跳到text10
...全文
32 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
Gelim 2003-09-01
  • 打赏
  • 举报
回复
上面的有一点问题!再看看这个吧!

Private Sub Text1_Change(Index As Integer)

Dim a() As Byte
a = StrConv(Text1(Index), vbFromUnicode)
If UBound(a) + 1 >= 16 Then
ReDim Preserve a(15) As Byte
Text1(Index).Text = StrConv(a, vbUnicode)
If Index < Text1.UBound Then
Text1(Index + 1).SetFocus
Text1(Index + 1).SelStart = Len(Text1(Index + 1))
End If
End If

End Sub
Gelim 2003-09-01
  • 打赏
  • 举报
回复
下面的程序可以解决你一定要中文8个,英文16个的要求


Private Sub Text1_Change(Index As Integer)

Dim a() As Byte
a = StrConv(Text1, vbFromUnicode)
If UBound(a) + 1 >= 16 Then
ReDim Preserve a(15) As Byte
Text1(Index).Text = StrConv(a, vbUnicode)
If Index < Text1.UBound Then
Text1(Index + 1).SetFocus
End If
End If

End Sub
踏平扶桑 2003-09-01
  • 打赏
  • 举报
回复
以上回复方法,几呼都好用
但是共同存在一个问题啊!
就是中文也是8个,英文也是8个
我想要的是中文为8个,英文是16个
谢谢了!


那好像要进行编码转换了,默认得vb中汉字和英文是一样得
或者你检测每个字符得ascii值,汉字是负数:)
smallbeggar2002 2003-09-01
  • 打赏
  • 举报
回复
而且,Text1需要空两个格
smallbeggar2002 2003-09-01
  • 打赏
  • 举报
回复
以上回复方法,几呼都好用
但是共同存在一个问题啊!
就是中文也是8个,英文也是8个
我想要的是中文为8个,英文是16个
谢谢了!
penglc 2003-08-22
  • 打赏
  • 举报
回复
建议把那些text做成控件数组,有新增加text控件时下面代码不用改动仍可以通用:

Private Sub Text1_Change(Index As Integer)

'如果输入或粘贴过来的字符小于8位,退出过程
If Len(Text1(Index).Text) < 8 Then Exit Sub

'如果大于8位,则取前8位
If Len(Text1(Index).Text) > 8 Then Text1(Index).Text = Left(Text1(Index).Text, 8)

'如果还有下一个text数组控件,则跳焦点
If Index < Text1.UBound Then
Text1(Index + 1).SetFocus '下一个text获得焦点
End If


End Sub
xingnup 2003-08-22
  • 打赏
  • 举报
回复
应该是用控件数组比较方便
didishu0807 2003-08-22
  • 打赏
  • 举报
回复
首先吧text控件的maxlength设为8
Private Sub Text1_Change()
If Len(Text1.Text) = 8 Then Text2.SetFocus
End Sub
```
Private Sub Text9_Change()
If Len(Text9.Text) = 8 Then Text10.SetFocus
End Sub


lihonggen0 2003-08-22
  • 打赏
  • 举报
回复
用控件数组比较方便
LCAAA 2003-08-22
  • 打赏
  • 举报
回复
你可以这样判断text1的长度是不是8,如果是就把光标定位到text2上就可以了。

lihonggen0 2003-08-22
  • 打赏
  • 举报
回复
Private Sub Text1_Change()
If Len(Text1.Text) = 8 Then Text2.SetFocus
End Sub

Private Sub Text2_Change()
If Len(Text2.Text) = 8 Then Text3.SetFocus
End Sub
饮水需思源 2003-08-22
  • 打赏
  • 举报
回复
同意楼上的方法,可以用控件数组来实现
射天狼 2003-08-22
  • 打赏
  • 举报
回复
也可以定义一个设置焦点的函数,然后在每个TEXT控件里调用.
Private Sub Text1_KeyPress(KeyAscii As Integer)
SetTextFocus Text2, Text1
End Sub

Private Sub SetTextFocus(txtDes As TextBox, txtSrc As TextBox)
If Len(txtSrc.Text) = 8 Then txtDes.SetFocus
End Sub
射天狼 2003-08-22
  • 打赏
  • 举报
回复
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Len(Text1.Text) = 8 Then Text2.SetFocus
End Sub

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧