想用txtbox来限定输入温度的问题!
请大家帮帮忙!
我想用txtbox来限定输入温度,例如12°C 或者-12°C。这里就有一个问题啦!
负号只能够限定在第一位被输入,其它位不可以输入,其它位只可以输入数字!请教教我!~~多谢!
问题点数:0、回复次数:9Top
1 楼wynbfqny(今无心)回复于 2005-04-01 08:55:52 得分 0
txt_keypress 事件里加判断了
如果输入不在第一位,只允许输入数字,如果是第一位则允许输入数字或正负号Top
2 楼wwwpdh(苹果树)回复于 2005-04-01 09:05:11 得分 0
我就是不懂如何判断是第几位啊!可以把代码写给小弟吗,我是初学者啊!!Top
3 楼cxa_2002(萱)回复于 2005-04-01 09:21:03 得分 0
用户名只允许输入数字1-9,按其他键无法输入字符
If KeyAscii <> 8 Then
If (KeyAscii > 57) Or (KeyAscii < 48) Then
Beep
KeyAscii = 0
End If
End If
Top
4 楼wwwpdh(苹果树)回复于 2005-04-01 09:27:27 得分 0
不是这样啊!我把问题在说清楚些!我要的是在第一位只可以输入数字和负号,其它位只能够是数字,而且,我已经限定了textbox里面的长度是3!Top
5 楼xushixu(civi)回复于 2005-04-01 09:36:13 得分 0
寫個function對每位進行截取字符﹐進行判斷
如下﹕
private sub txtbox_input()
if len(txtbox)=1Top
6 楼xushixu(civi)回复于 2005-04-01 09:39:17 得分 0
暈沒寫完就發了﹗
private sub txtbox_input()
If Len(txtbox)>1 then
If KeyAscii <> 8 Then
If (KeyAscii > 57) Or (KeyAscii < 48) Then
Beep
KeyAscii = 0
End If
End If
End If
End Sub
Top
7 楼cy_nwau(小人物)回复于 2005-04-01 09:39:42 得分 0
以下代码放在文本框的keypress事件中:
dim s as string*1
s=chr(keyascii)
if text1="" and instr("-123456789",s)=0 then
keyascii=0
exit sub
endif
If KeyAscii <> 8 Then
If (KeyAscii > 57) Or (KeyAscii < 48) Then
KeyAscii = 0
End If
End If
Top
8 楼cy_nwau(小人物)回复于 2005-04-01 09:40:07 得分 0
以下代码放在文本框的keypress事件中:
dim s as string*1
s=chr(keyascii)
if text1="" and instr("-123456789",s)=0 then
keyascii=0
exit sub
endif
If KeyAscii <> 8 Then
If (KeyAscii > 57) Or (KeyAscii < 48) Then
KeyAscii = 0
End If
End If
Top
9 楼wwwpdh(苹果树)回复于 2005-04-01 20:54:16 得分 0
不是这样的啊!我想的是输入温度啊!例如我要输入-12°C,那么长度是限定了3位,第一位只可以是负号和数字,后两位只可以是数字!负号不可以在第2,3位被输入!Top




