asp
学习笔记第二章
1.声明变量 Dim
Dim str1,str2 声明两个变量。
str1="111" 将str1初始化为字符串变量
num1=1 将num1初始化为数值变量
(注:带" " 的为字符串变量,不带的为数值变量)
练习:
<%
Dim name1,name,h1,num1
h1 = " 你好!"
name1 = "miaolin"
num1 = 12
name = name1 & h1 & " 现在时间是" & num1 & "点"
Response.Write name
Response.Write"<p>"
%>
2.要求变量在使用前必须声明的语句<% Option Explicit %>
一般作为脚本语句的第一行。
3.创建常量语句Const
例:Const MyAge = 22
4.条件语句Select Case 和 if...then...else
例:
<%
Dim i
i = DatePart("h",now) '捕捉当前时间的小时数(函数)
select case i
case 0,1,2,3,4,5
Response.Write "凌晨好"
case 6,7,8,9,10,11
Response.Write "上午好"
End select
%>
条件语句if...then....else
例:
<%
...
...
if i<6 then
Response.Write "凌晨好"
elseif i>=6 and i<=11 then
Response.write "上午好"
else
Response.write "晚上好"
End if
%>
5.循环语句
(1)do....loop 条件为true时循环
格式一:
do while...
....
loop
(判断在循环)
格式二:
do....
...
loop while...
(先运行一次在判断)
(2)for循环语句
格式 for i = 1 to n step m (m=1时可以省略step参数)
......
next
(注:循环体内可使用 exit for 语句强行退出)
6.过程
(1)sub过程 不返回值
sub XXX()
...
end sub
(2)funciont 过程 返回值
function 函数名(参数)
....
function end function
文章引用自: