1. Date and time

<html>
<body>

Today's date is: <%response.write(date())%>.
<br>
The server's local time is: <%response.write(time())%>.

</body>
</html>

 

2. Get the name of a day

<html>
<body>

<p>
VBScripts' function <b>WeekdayName</b> is used to get a weekday:
</p>
<%
response.Write(WeekDayName(1))
response.Write("<br>")
response.Write(WeekDayName(2))
%>

<p>Abbreviated name of a weekday:</p>
<%
response.Write(WeekDayName(1,true))
response.Write("<br>")
response.Write(WeekDayName(2,true))
%>

<p>Current weekday:</p>
<%
response.Write(WeekdayName(weekday(date)))
response.Write("<br>")
response.Write(WeekdayName(weekday(date), true))
%>

</body>
</html>

 

3. Get the name of a month 

<html>
<body>

<p>VBScripts' function <b>MonthName</b> is used to get a month:</p>
<%
response.Write(MonthName(1))
response.Write("<br>")
response.Write(MonthName(2))
%>

<p>Abbreviated name of a month:</p>
<%
response.Write(MonthName(1,true))
response.Write("<br>")
response.Write(MonthName(2,true))
%>

<p>Current month:</p>
<%
response.Write(MonthName(month(date)))
response.Write("<br>")
response.Write(MonthName(month(date), true))
%>

</body>
</html>

 

4. Get todays' day and month

<html>
<body>

Today it is
<%response.write(WeekdayName(weekday(date)))%>,
<br>
and the month is
<%response.write(MonthName(month(date)))%>

</body>
</html>

 

5. Countdown to year 3000

<html>
<body>

<p>Countdown to year 3000:</p>

<p>
<%millennium=cdate("1/1/3000 00:00:00")%>

It is
<%response.write(DateDiff("yyyy", Now(), millennium))%>
years to year 3000!
<br>
It is
<%response.write(DateDiff("m", Now(), millennium))%>
months to year 3000!
<br>
It is
<%response.write(DateDiff("ww", Now(), millennium))%>
weeks to year 3000!
<br>
It is
<%response.write(DateDiff("d", Now(), millennium))%>
days to year 3000!
<br>
It is
<%response.write(DateDiff("h", Now(), millennium))%>
hours to year 3000!
<br>
It is
<%response.write(DateDiff("n", Now(), millennium))%>
minutes to year 3000!
<br>
It is
<%response.write(DateDiff("s", Now(), millennium))%>
seconds to year 3000!
</p>

</body>
</html>

 

6. Calculate the day which is n days from today

<html>
<body>

<%
response.write(DateAdd("d",30,Date()))
%>

<p>
This example uses <b>DateAdd</b> to calculate a date 30 days from today.
</p>
<p>
Syntax for DateAdd: DateAdd(interval,number,date).
</p>

<%
response.write(DateAdd("d",10,Date()))
%>

<p>
This example uses <b>DateAdd</b> to calculate a date 10 days from today.
</p>
<p>
Syntax for DateAdd: DateAdd(interval,number,date).
</p>

</body>
</html>

 

7. Format date and time

<html>
<body>

<%
response.write(FormatDateTime(date(),vbgeneraldate))
response.write("<br>")
response.write(FormatDateTime(date(),vblongdate))
response.write("<br>")
response.write(FormatDateTime(date(),vbshortdate))
response.write("<br>")
response.write(FormatDateTime(now(),vblongtime))
response.write("<br>")
response.write(FormatDateTime(now(),vbshorttime))
%>

<p>
Syntax for FormatDateTime: FormatDateTime(date,namedformat).
</p>

</body>
</html>

 

8. Is this a date?

<html>
<body>

<%
somedate="10/40/11"
response.write(IsDate(somedate))
response.write("<br>")
somedate="18/30/99"
response.write(IsDate(somedate))
response.write("<br>")
somedate="10/30/99"
response.write(IsDate(somedate))
%>

</body>
</html>

 

[출처] www.w3schools.com/asp/asp_examples.asp

ASP에서 레코드셋을 이용하여 레코드를 이동하는 방법

 

DB 오픈할 때 커서 타입을 지정해 줘야 한다.

 ex) Rs.Open SQL, DB, 1 (MoveNext와 MoveFirst만 사용시에는 1없어도 됨)

다음 레코드로 이동 rs.MoveNext
이전 레코드로 이동 rs.MovePrevious
처음 레코드로 이동 rs.MoveFirst
마지막 레코드로 이돌 rs.MoveLast
총 레코드 갯수 구하기 rs.RecordCount

 

[출처] sunkyun.com/community/bbs/?t=N

배열 변수 Rs.GetRows()

배열은 2차원 배열로 만들어 지며 1차원 값은 원하는 컬럼 값이고 2차원은 컬럼에 해당하는 값이 들어간다.

 

Column 크기 : UBound (배열 변수, 1)

Row 크기 : UBound (배열 변수, 2)

* 배열은 0부터 시작하기 때문에 1 차이가 남


 

sql = "select * from emp"
oraRec.Open sql, oraConn, 1

a_arr   = oraRec.getrows
a_column = ubound(a_arr, 1)
a_row = ubound(a_arr, 2)

response.Write "a_column = " & a_column & "<br/>"
response.Write "a_row = " & a_row & "<br/>"

 

[출처] blog.naver.com/mavis5/10081206806

If문

-- Java, C에서의 if문 사용법
if(조건) {

} else if {

} else {

}

-- ASP에서의 if문 사용법
If 조건 Then
	결과
Else
	결과
End If

※ 보통 if문에서 비교할 때는 '=='으로 비교를 하지만 ASP에서는 '='로 비교를 한다.

※ Else If의 경우 ElseIf로 띄어쓰기 없이 붙여줘야 한다. (EndIf 말고 ElseIf)

 

For문

-- Java, C에서의 for문 사용법
for (int i=0; i<=z; i++) {
	반복될 문장
}

-- ASP에서의 for문 사용법
For i=0 To Z Step 1 
	반복될 문장
Next

 

Do While문

-- Do While문
<%
	a = 1
    
    Do While a < 10	-- a가 10보다 작다면 (조건식이 참이라면)
    	response.write a & "<br>"
        a = a + 1
    Loop
%>

-- Do Until문
<% 
	a = 1
    
    Do Until a > 10  -- a가 10보다 클때까지 (조건식이 거짓이라면)
    	response.write a & "<br>"
        a = a + 1
    Loop
%>

-- Do Loop While문 : 최소 1번 이상 실행 해야 하는 경우에 사용
<%
	a = 1
    
    Do
    	response.write a & "<br>"
        a = a + 1
    Loop while a > 10
%>

 

BOF는 Begin Of File로 레코드 셋의 시작, EOF는 End Of File로 레코드 셋의 끝을 의미한다.

레코드가 하나가 아닌 경우 가상 테이블의 형태로 레코드셋이 저장되고 그 시작과 끝을 구분해주는 것이 BOF와 EOF이다.

 

주로 DB에서 데이터를 불러오는 경우 사용

If Rs.EOF Or Rs.BOF Then
...(중략)
End If

 

DB에 데이터가 있는 경우 Rf.EOF와 RS.BOF는 false가 되고 데이터가 없는 경우 true가 된다.

일반적으로 아래처럼 EOF만 사용해서 데이터를 출력하는 데 많이 사용하고 있다.

If Not Rs.EOF Then
...(출력 데이터)
End If

if rs.BOF or rs.EOF then
  response.write "데이터가 존재하지 않습니다"
else
  response.write "데이터 출력"
end if

[출처] travelpark.tistory.com/51

페이지 단위로 인코딩을 설정하는 방법

이 경우 아래와 같이 코드를 페이지 최상단에 추가한다.

<%@Language="VBScript" CODEPAGE="65001" %>
<%
 
  Response.CharSet="utf-8"
  Session.codepage="65001"
  Response.codepage="65001"
  Response.ContentType="text/html;charset=utf-8"
%>

 

[출처] codelib.tistory.com/28

'프로그램 > ASP' 카테고리의 다른 글

[ASP] If문, For문, Do While문  (0) 2021.03.09
[ASP] BOF와 EOF의 의미  (0) 2021.03.09
[ASP] 기초 문법 실습하기  (0) 2021.03.03
ASP 기본 문법 I  (0) 2021.03.03
ASP 란 무엇인가?  (0) 2021.03.03

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"
%>

 

 

[출처] www.w3schools.com/asp/asp_examples.asp

'프로그램 > 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

 

1. Dim : 변수를 선언

2. Set : 개체를 선언

Handphone 개체의 사용 방법

1. Dim myPhone
2. Set myPhone = Server.CreateObject ("Telephone.Handphone")
3. myPhone.color = "white"
4. myPhone.number = "011-9971-88XX"
5. myPhone.call ("02-584-88XX")
6. myPhone.hangup ( )
7. Set myPhone = Nothing

 

1. myPhone이라는 변수 선언

2. Server.CreateObject 라는 메소드를 사용하여 Handphone 개체의 인스턴스를 만들어서 myPhone 이라는 변수에 저장

3, 4. 속성에 값을 할당하는 구문

5, 6. 메소드를 실행하는 구문

7. Set myPhone = Nothing 이라는 구문을 사용하여 개체의 인스턴스인 'myPhone'을 메모리에서 해제

 


 

3. IF ~ THEN : 만약 ~라면 (조건이 적은 경우)

IF intNumber = 1 THEN
   Response.Write "intNumber에 들어있는 수는 1입니다."
ELSEIF intNumber = 2 THEN
   Response.Write "intNumber에 들어있는 수는 2입니다."
ELSEIF intNumber = 3 THEN
   Response.Write "intNumber에 들어있는 수는 3입니다."
ELSE
   Response.Write "intNumber에 들어있는 수는 1, 2, 3이 아닌 다른 숫자입니다."
END IF

 

Response.Write : 현재 화면에 문자열을 출력하라는 함수

 


 

4. SELECT CASE : 만약 ~라면 (조건이 많은 경우)

SELECT CASE intNumber
CASE 1
   Response.Write "intNumber에 들어있는 수는 1입니다."
CASE 2
   Response.Write "intNumber에 들어있는 수는 2입니다."
CASE 3
   Response.Write "intNumber에 들어있는 수는 3입니다."
CASE 4
   Response.Write "intNumber에 들어있는 수는 4입니다."
CASE 5
   Response.Write "intNumber에 들어있는 수는 5입니다."
CASE 6
   Response.Write "intNumber에 들어있는 수는 6입니다."
CASE 7, 8, 9
   Response.Write "intNumber에 들어있는 수는 7, 8, 9 중 하나 입니다."
CASE 10
   Response.Write "intNumber에 들어있는 수는 10입니다."
CASE ELSE
   Response.Write "intNumber에 들어있는 수는 1부터 10 사이의 정수가 아닙니다."
END  SELECT

 


 

5. FOR ~ NEXT : 순환하면서 실행 (반복 횟수를 정확하게 알고 있을 때)

1부터 1000까지의 숫자를 화면에 출력하라는 명령어

DIM intLoop
FOR intLoop = 1 TO 1000 STEP 1
      Response.writer intLoop & "<BR>"
NEXT

[FOR~NEXT 구문의 형식]

FOR 
시작 TO STEP 증가
    반복되어 실행될 구문
NEXT

 


 

6. DO WHILE : 순환하면서 실행 (반복 횟수를 정확하게 알 수 없을 때)

1부터 1000까지의 숫자를 화면에 출력하라는 명령어

DIM intLoop
intLoop = 1 
DO WHILE
intLoop <= 1000                         // intLoop 변수에 담긴 숫자가 1000보다 같거나 작은 동안에는 계속 실행해라.
      Response.writer intLoop & "<BR>"
      intLoop = intLoop + 1                             // 대입 연산자
LOOP

[FOR~NEXT 구문의 형식]

FOR  
시작 TO  STEP 증가
    반복되어 실행될 구문
NEXT

 

 

출처 taeyo.net/lecture/Dukyoung/DYsASP06.asp

'프로그램 > ASP' 카테고리의 다른 글

[ASP] BOF와 EOF의 의미  (0) 2021.03.09
[ASP] 한글 깨짐 해결 방법  (0) 2021.03.08
[ASP] 기초 문법 실습하기  (0) 2021.03.03
ASP 란 무엇인가?  (0) 2021.03.03
ASP와 ASP.NET의 차이점  (0) 2021.03.03

 

1. 서버와 클라이언트7
한 컴퓨터에서 다른 컴퓨터로 어떤 문서 및 정보를 보여달라고 요구했을 때 그 자료를 요청한 컴퓨터를 '클라이언트', 제공해 주는 컴퓨터를 '서버'라고 한다.
서버(Server)는 '제공자, 제공하는 것'이여,
클라이언트(Client)는 '의뢰인, 고객'을 의미한다.

2. 웹서버 (Web Server)
웹 서버란 '웹 서비스를 제공하는 서버'라고 한다.
서버는 서버인데, 웹(www) 상에 있는 서버이기 때문에 인터넷만 연결되어 있다면 어느 나라 어느 장소에 있는 사람이라도 그 곳을 방문 할 수 있다.

3. IIS (Internet Information Services)
IIS란 ASP 페이지가 실행될 수 있는 환경을 제공하는 '웹 서버 프로그램'의 이름이다.

웹 서버의 의미를 '하드웨어(컴퓨터 본체)' 라고 한다면,
IIS란 '소프트웨어(프로그램)'을 의미한다고 생각하면 된다. 

 

ASP란 무엇인가?

ASP란 'Active Server Pages'의 약자이며, '동적으로 서버에서 작동하는 페이지'로 해석한다.

 

<HTML>
<HEAD>
<TITLE> Welcome To Dukyoung.net </TITLE>
</HEAD>
<BODY>
<CENTER>
<% IF Hour(Now) < 12 THEN %>
지금은 오전입니다.
<% ELSE %>
지금은 오후입니다.
<% END IF%>
</CENTER>
</BODY>
</HTML>

 

<% IF Hour(Now) < 12 THEN %>

1. Now() 함수

컴퓨터 시스템에서의 '현재 시간'을 표시

 

2. Hour() 함수

24시간으로 환산한 '시간'을 나타내는 인자가 들어감. 

 

3. IF ~ THEN (조건문)

'만약 ~ 이라면' 이라는 뜻을 가짐. IF와 THEN 사이에는 '참' 또는 '거짓'을 판별할 수 있는 조건이 들어감.

IF 조건 THEN
참일 때의 처리 실행
ELSE
거짓일 때의 처리 실행
END IF

 

1. ASP는 '<%' 으로 시작하여 '%>'으로 끝난다.
2. 클라이언트들은 오직 ASP 코드가 실행된 후의 HTML 페이지만을 볼 수 있다.

 

출처  taeyo.net/lecture/Dukyoung/DYsASP05.asp

'프로그램 > ASP' 카테고리의 다른 글

[ASP] BOF와 EOF의 의미  (0) 2021.03.09
[ASP] 한글 깨짐 해결 방법  (0) 2021.03.08
[ASP] 기초 문법 실습하기  (0) 2021.03.03
ASP 기본 문법 I  (0) 2021.03.03
ASP와 ASP.NET의 차이점  (0) 2021.03.03

+ Recent posts