ASP는 세미콜론(;) 안 붙이기
문자열 출력
<html>
<body>
<%
response.write("My first ASP script")
%>
</body>
</html>
변수와 문자열 출력
변수와 문자를 연결할 땐 &을 사용
<html>
<body>
<%
dim name
name="Donald Duck"
response.write("My name is : " & name)
%>
</body>
</html>
배열
배열 famname(0)부터 famname(5)까지 출력하는 for문
<html>
<body>
<%
Dim famname(5), i
famname(0) = "A"
famname(1) = "B"
famname(2) = "c"
famname(3) = "D"
famname(4) = "E"
famname(5) = "F"
For i = 0 to 5
responnse.write(famname(i)& "<br />")
Next
%>
</body>
</html>
IF문
현재 시간을 기준으로 12시보다 이전이면 Good morning 을 출력하고 12시 이후면 Good Day 를 출력하는 if문
<html>
<body>
<%
dim h
h=hour(now())
response.write("<p>" & now())
response.write("</p>")
if h<12 then
response.write("Good morning")
else
response.write("Good day")
end if
%>
</body>
</html>
FOR문
<h1>부터 <h6>까지의 문장을 크기별로 나타내는 for문
<html>
<body>
<%
dim i
for i=1 to 6
response.write(" <h" & i & ">Heading " & i & "</h" & i & ">")
next
%>
</body>
</html>
FOR EACH문
<html>
<body>
<%
Dim cars(2)
cars(0) = "Volvo"
cars(1) = "Saab"
cars(2) = "BMW"
For Each x In cars
response.write(x & "<br>")
Next
%>
</body>
</html>
리턴값이 없는 함수
<html>
<head>
<%
sub vbproc(num1, num2)
response.write(num1*num2)
end sub
%>
</head>
<body>
<p>Result:<%vbproc 3, 4%> </p>
</body>
</html>
리턴값이 있는 함수
함수명과 동일한 변수명에 리턴하고자 하는 값을 넣어 함수를 종료하면 됨
<html>
<body>
<%
function func (val1, val2)
func = val1 * val2
end function
response.write "func(25, 10) : " & func(25, 10)
%>
</body>
</html>
페이지 이동
<%
response.redirect "http://www.naver.com"
%>
'프로그램 > ASP' 카테고리의 다른 글
[ASP] BOF와 EOF의 의미 (0) | 2021.03.09 |
---|---|
[ASP] 한글 깨짐 해결 방법 (0) | 2021.03.08 |
ASP 기본 문법 I (0) | 2021.03.03 |
ASP 란 무엇인가? (0) | 2021.03.03 |
ASP와 ASP.NET의 차이점 (0) | 2021.03.03 |