vb 新手问题

[复制链接]
查看11 | 回复4 | 2008-7-5 08:59:55 | 显示全部楼层 |阅读模式
求1+2+3+。。。。+n的和
dim counter as integer,s as integer, n as integer
counter=0:s=0
n=text1.text
Do
counter=counter+1
s=s+counter
if counter=n then exit Do
loop
text2.text=s
end sub
这个代码里面,如果把if句分行成为
if counter=n then
exit DO
为什么就运行错误了??
这有什么区别吗??

回复

使用道具 举报

千问 | 2008-7-5 08:59:55 | 显示全部楼层
if counter=n then exit Do 是if counter=n then exit doend if的简写if 后面要有end if 配对的...就if counter=n thenexit do例外
回复

使用道具 举报

千问 | 2008-7-5 08:59:55 | 显示全部楼层
这说明你不细心,提示运行错误的时候,软件一定告诉你 错误是 if 没有 end if,而你却没有看到。
回复

使用道具 举报

千问 | 2008-7-5 08:59:55 | 显示全部楼层
当然有了,如果在一行写,IF语句就不用写结束语(END IF )如果你分行写了,那么就在下面加上end if 就可以了。
回复

使用道具 举报

千问 | 2008-7-5 08:59:55 | 显示全部楼层
分了行之后要加上End if.if counter=n then exit DO end if
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行