曲径通幽论坛

标题: 自定义子程序的方法 [打印本页]

作者: easy    时间: 2013-4-4 11:28
标题: 自定义子程序的方法
自定义子程序的方法依下面的形式:
sub sub_name(参数)
子函数体
end sub
子程序和函数的区别在于:子程序是一个没有返回值的函数。

测试代码
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<[email=%@LANGUAGE=]%@LANGUAGE="VBSCRIPT[/email]" CODEPAGE="65001" %>
<%
sub CountN(n)
dim c

for i = 1 to n
  c = c + i
next
response.Write("result: " & c & "<br />")
end sub
call CountN(5)
countN 6
%>
</body>
</html>
运行结果:
result: 15
result: 21
在上面的程序中,使用了两种调用子程序的方法,一种是带 call 关键字的;一种是不带 call 的,不带 call 的。




欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2