1,451
社区成员
发帖
与我相关
我的任务
分享
Private Sub Text2_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii >= vbKey0 And keyaysii <= vbKey9 Then
If Index < Text2.UBound Then
Index = Index + 1
End If
ElseIf KeyAscii = vbKeyBack Then
Text2(Index).Text = ""
If Index > Text2.LBound Then
Index = Index - 1
End If
Else
KeyAscii = 0
End If
Text2(Index).SetFocus
Text2(Index).SelStart = 0
Text2(Index).SelLength = Len(Text2(Index).Text)
End Sub
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
Select Case KeyAscii
Case 8
KeyAscii = 0
If Len(Text1(Index).Text) > 0 Then
Text1(Index).Text = Left(Text1(Index).Text, Len(Text1(Index).Text) - 1)
Text1(Index).SelStart = Len(Text1(Index).Text)
Else
If Index > 0 Then
Text1(Index - 1).SetFocus
Text1(Index - 1).SelStart = Len(Text1(Index - 1).Text)
Text1(Index - 1).SelLength = 0
End If
End If
End Select
End Sub
'方法1,具体删除字符交给系统
if text1(index)="" then
text1(index-1).selstart=len(text1(index-1).)
text1(index-1).setfocus
end if
'方法2,直接删除
text1(index-1).=""
text1(index-1).setfocus
注意判断处理索引越界