问题1 Function Fun_KPS只能输入0到9(KeyAscii As Integer) As Integer
If (KeyAscii < Asc("0") Or KeyAscii > Asc("9")) And KeyAscii <> 8 And KeyAscii <> 13 And KeyAscii <> 3 And KeyAscii <> 22 And KeyAscii <> 24 And KeyAscii <> 26 Then Fun_KPS只能输入0到9 = 0 MsgBox "此处只能输入0到9的数字!", , "系统提示" Else Fun_KPS只能输入0到9 = KeyAscii End IfEnd Function
问题2 Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) If Len(Trim(Text1.Text)) = 2 Then Text2.SetFocus End If End Sub
问题3 Private Sub Text2_GotFocus() MsgBox Right(Trim(Text1.Text), 1) End Sub或者 Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) If Len(Trim(Text1.Text)) = 2 Then Text2.SetFocus MsgBox Chr(KeyCode) End If End Sub
1.FUNction valitext(keyin as integer ,validatastring,Editable as boolean ) as integer dim validatalist as string dim keyout as integer if editable=true then validatalist=ucase(validatastring)&chr(8) else validatalist=ucase(validatastring) end if if instr(1,validatalist,ucase(chr(keyin)),1)>0 then keyout=keyin else keepout=0 beep end if valitext=keyout end functionprivate text1_keypress(keyascii as integer) keyascii=valitext(keyascii,"0123456789",true) end private
2. private sub text1_keypress(keyascii as integer) if keyascii=13 then if len(text1.text)=3 then text2.setfocus end if end if end sub
第一个问题这样最简单吧 If Not IsNumeric(TxtBackodo.Text) Then MsgBox "抱歉!您必须输入0-9的数字", vbOKOnly, "警告" end if
If Not IsNumeric(TxtBackodo.Text) Then beep end if
Function Fun_KPS只能输入0到9(KeyAscii As Integer) As Integer
If (KeyAscii < Asc("0") Or KeyAscii > Asc("9")) And KeyAscii <> 8 And KeyAscii <> 13 And KeyAscii <> 3 And KeyAscii <> 22 And KeyAscii <> 24 And KeyAscii <> 26 Then
Fun_KPS只能输入0到9 = 0
MsgBox "此处只能输入0到9的数字!", , "系统提示"
Else
Fun_KPS只能输入0到9 = KeyAscii
End IfEnd Function
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If Len(Trim(Text1.Text)) = 2 Then
Text2.SetFocus
End If
End Sub
Private Sub Text2_GotFocus()
MsgBox Right(Trim(Text1.Text), 1)
End Sub或者
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If Len(Trim(Text1.Text)) = 2 Then
Text2.SetFocus
MsgBox Chr(KeyCode)
End If
End Sub
dim validatalist as string
dim keyout as integer
if editable=true then
validatalist=ucase(validatastring)&chr(8)
else
validatalist=ucase(validatastring)
end if
if instr(1,validatalist,ucase(chr(keyin)),1)>0
then
keyout=keyin
else
keepout=0
beep
end if
valitext=keyout
end functionprivate text1_keypress(keyascii as integer)
keyascii=valitext(keyascii,"0123456789",true)
end private
if keyascii=13 then
if len(text1.text)=3 then
text2.setfocus
end if
end if
end sub
If Not IsNumeric(TxtBackodo.Text) Then
MsgBox "抱歉!您必须输入0-9的数字", vbOKOnly, "警告"
end if
beep
end if
2,dlpseeyou(豆子) 10
3.通过SoHo_Andy(冰)的答案自己推出来的,原方案不怎么好用。 8感谢:cooket(见光死) 和tianyxy(天涯夕阳)的支持。