新卒から文系エンジニア→人材業界に転職した人のブログ

新卒から文系エンジニア→人材業界に転職。技術・スキルがないためブログを通して勉強。その後、IT業界の業界知識が活かせる人材業界へ。異業種×異職種の転職経験有り。

このエントリーをはてなブックマークに追加

【ASP】ASP入門 ~文字の出力・HTMLの出力・条件分岐・繰り返し・ユーザ定義関数~

【今回の紹介】

掲題の通り。
業務でASPを使っていきそうなので基礎的な部分から学習をしていくのでそのメモを残します。

以下のサイトを参考に学習
サンプルコードで学ぶASP

【内容】

ASPとは

 
 ・Active Server Pages の略
・html,javascript,VBscriptを組み合わせてWEBページを動的にすること 
 参考:ウィキペディア


■サーバサイド

 ・サーバサイドはVBscriptで書く
 ※VBscript書けるようになったら、いろいろ応用がききそうなので、
  今回はここを中心に学習を行う




VBscript

 ①VBscriptでは以下の用のことができるらしい
  ・クライアントから受け取った値を加工する
  ・加工した値をブラウザに出力   

 ②サーバサイドでHTMLを生成する意味として
  ・ユーザの操作によってページの表示を動的にかえることができる
  ・クライアント側(javascript)でも可能だが、サーバ側で行うとブラウザの違いがでないこと
  ・ネットワークに負荷を軽減

ASPIISの設定は以下の参照

 参考サイト


ASPにサンプルを書く

 
 ①文字の出力
 ②HTMLの出力
 ③繰り返し処理
 ④条件分岐
 ⑤ユーザ定義の関数の使用
functionとsubの違い
sub:返り値なし 
function:返り値あり 


【参考ソース】



 ①文字の出力

<html>
	<body>
	<%
	Response.Write "test"& vbCrLf
	%>
	<% 'どちらでも出力可能%>
	<%="test2"%>
	</body>
</html>





②HTMLの出力

<html>
	<body>
	<%
	Response.Write "<h1>見出し1です</h1>" & vbCrLf
	Response.Write "<h2>" & vbCrLf
	Response.Write "見出し2です" & vbCrLf
	Response.Write "</h2>" & vbCrLf
	%>
	</body>
</html>



③繰り返し処理

<html>
	<body>
	<%
	for i=0 to 10
	Response.Write "<h1>見出し" & i & "です</h1>" & vbCrLf
	next
	%>
	</body>
</html>




 ④条件分岐

<html>
	<body>
	<%
	i=0
	if i=0 then
		response.write "iは0です"
	else
		response.write "iは0以外です"
	end if
	%>
	
	<%
	k=2
	select case k
	
	case 1
		response.write "1"
	case 2
		response.write "2"
	case 3
		response.write "3"
	end select
	%>
	
	</body>
</html>



⑤ユーザ定義の関数の使用

<html>
	<body>
	<%
	'---引数なし関数----
	sub error_messeage
	response.write "<p>エラーが発生しました</p>"
	end sub
	'---引数なし関数----
	
	'---引数あり関数----
	sub error_messeage2(val)
	response.write "<p>" & val & "でエラーが発生しました</p>"
	end sub
	'---引数あり関数----
	
	'---返り値あり関数----
	function error_messeage3(val)
	error_messeage3=""
	
	if val <> "test" then
		error_messeage3=true
	else
		error_messeage3=false
	end if
	end function	
	'---返り値あり関数----
	
	error_messeage()
	error_messeage2("ボタン1")	
	response.write error_messeage3("test")
	
	%>
	
	</body>
</html>
.hatena-module:nth-of-type(10) { background: transparent; } .hatena-module:nth-of-type(10) .hatena-module-title{ display: none; } .hatena-module:nth-of-type(10) .hatena-module-body { padding: 0; }