每一层要用end if来结束本层判断。
if<条件>then
<语句>
<语句>
...
End
if
与c语言不同,(vb)的条件语句更符合英语的语法,如果then后面所跟的语句只有一条,可以写成:
if
<条件>
then
不用end
if
有时还用到:
if<条件>then
<语句>
Else
<语句>
end
if
还可以在else里再嵌套if语句,如
if
<条件>
then
<语句>
else
if
<语句>
else
<语句>
end
if
Private Sub Text1_KeyPress(keyascii As Integer)
Select Case Len(Text1.Text)
Case 0
If keyascii < 49 Or keyascii > 57 Then keyascii = 0
Case 1
If keyascii < 48 Or keyascii > 57 Then
If keyascii <> 8 Then
keyascii = 0
End If
End If
Case Else
If keyascii = 8 Then
Else
keyascii = 0
End If
End Select
End Sub
我这个测试了效果很好 在显示前做判断
检测事件是在文本框中的change事件中判断,也就是说只要文本框有改变就检测!
如果把其中的
and
改写成
or
就可以判断其中一个文本是否为空!
private
sub
text1_change()
'判断文本框最快的速度还是判断它的长度是否为0
if
len(text1.text)=0
and
len(text2.text)=0
then
image5.visible
=
false
else
image5.visible
=
true
end
if
end
sub
private
sub
text2_change()
if
len(text1.text)=0
and
len(text2.text)=0
then
image5.visible
=
false
else
image5.visible
=
true
end
if
end
sub
完美财经网
http://www.wmcjw.cn
dim a
a=int(a)
a=inputbox("输入数值")
if a <100
moveto 文本的坐标
else
moveto 非文本的坐标
endif