VB高手帮忙看一下这段程序什么意思?

来源:百度知道 编辑:UC知道 时间:2024/05/12 12:26:18
private sub form_click()
x=100:a=10:b=20:ok1=true:ok2=false
if a<b then
if b<>15 then
if not ok1 then
x=1
else
if ok2 then x=10
x=-1
end if
end if
end if
print x
end sub
if not ok1 then
和下面的if ok2 then x=10
假设不是一样的,结果不一样,是怎么回事?

private sub form_click() private 表示函数私有
x=100:a=10:b=20:ok1=true:ok2=false 100给X 10给A 20给B OK1是真值 OK2是假值
if a<b then 如果A〈B
if b<>15 then 如果不等于15
if not ok1 then 如不是OK!
x=1 X=1
else 否则
if ok2 then x=10 如果OK2 且X=10 X=-1
x=-1
end if 结束IF
end if 结束IF
end if 结束IF
print x 打印 X
end sub

if not ok1 then
和下面的if ok2 then x=10

not OK1是OK1变量不为真时

if ok2 then x=10这句是OK2为真时X=10。因为这是写成了一句所以后面不需要end if 结束语。

你的代码不知道写出来有什么用。写这么长,还不如写一个固定的。当变量都为常量。布尔变量也都是固定死了没有过程去更改。
如果A大于B X=100
如果A小于B,而B又等于15,X=100
你的OK1永远都是真,OK2永远都是假。

答案:x=-1

if a<b then
if b<>15 then
if not ok1 then 'OK1取反,即false,以下if不执行
x=1
else
if ok2 then x=10 'OK2=false,所以也不执行
x=-1 '当做else...刚才看错。。。
end if
end if
end if