出来るのだASP Q&A掲示板(過去LOG)
訪問数 52046
昨日 889
今日 776 【PR】 パソコン入門からIT専門書まで幅広く取り揃えています。セブン-イレブン受取り手数料無料のセブンアンドワイ。 |
![]() ![]() ![]() ![]() ![]() |
[5604] ありがとうございす。教えの通り関数でやって、ちゃんと表示されたのですが・・・・・ |
投稿者:さとしさん 2006/01/20 13:09:27 |
いつもご教示ありがとうございます。関数でやってみました。けれども、ソースがひどいもので。 ----祝日設定-------------------------の部分をどうにか、簡略化 したいのですが、何か方法はあるでしょうか。スマートなソースにしたいと思っているのですが、何かアドバイスもらえると、幸いです。失礼します <%@ language=vbscript %> <% Option Explicit %> <% '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ '変数定義 '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ' --- 変数の定義 ------------------------------------------------------------- Dim ilastday '目的月の最終日 Dim idate '週の一日目 Dim iyear ' 入力パラメータ年(入力値がない場合当年) Dim imonth ' 入力パラメータ月(入力値がない場合当月) ' ------------------------------------------------------------- 変数の定義 --- ' --- 定数の定義 ------------------------------------------------------------- Const MINI_YEAR = 0 '最小値チェック用”年” Const MAX_YEAR = 9999 '最大値チェック用”年” Const MINI_MONTH = 1 '最小値チェック用”月” Const MAX_MONTH = 12 '最大値チェック用”月” ' ------------------------------------------------------------- 定数の定義 --- '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ '初期処理 '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ' 入力年を保存。ただし、チェックエラー時は当年を設定する。 iyear = Request.Form ("year") ' 入力パラメータのNullチェック If Request.Form("year") = "" Then iyear = year(now) Else iyear = Request.Form("year") End if ' 入力パラメータが数値の場合 If Isnumeric(iyear) Then ' 入力パラメータの範囲チェック If MINI_YEAR > iyear and MAX_YEAR < iyear Then iyear = year(now) End if ' 入力パラメータが数値以外の場合 Else iyear = Request.Form("year") End if ' 入力月を保存。ただし、チェックエラー時は当月を設定する。 imonth = Request.Form("month") ' 入力パラメータのNullチェック If Request.Form("month") = "" Then imonth = month(now) Else imonth = Request.Form("month") End if ' 入力パラメータが数値の場合 If isnumeric(imonth) Then If MINI_MONTH >= imonth and MAX_MONTH <= imonth Then imonth = month(now) End if Else imonth = month(now) End if %> <html> <head> <title>カレンダー表示</title> </head> <body> <h2>ScheduleCalender</h2> <% '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ '処理開始 '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ '週の一日目計算と月の最終日計算 idate = 1-Weekday(Dateserial(iyear,imonth,1))+1 ilastday = Day(Dateserial(iyear,imonth+1,1-1)) Response.Write "<div>西暦" & iyear & "年" & imonth & "月</div>" 'カレンダ作成開始 Response.Write "<table border=3>" Response.Write "<tr>" Dim j '曜日欄の作成 For j = 0 To 6 Response.Write "<td width=50 height=25 align=center>" If (Weekday(j) = 7) Then Response.Write "<font color=red>" End if If (Weekday(j) = 6) Then Response.Write "<font color=blue>" End If Response.Write Weekdayname(j+1,true) Response.Write "</td>" Next Response.Write "</tr>" ' カレンダーの月の1日目から月の最終日の表示 Dim i ' カレンダー表示の行(添え字) For i = 0 To 5 Response.Write "<tr>" For j = 0 To 6 ' 1週間(0:日,1:月・・・6:土) If idate > 0 and idate <= ilastday Then 'カレンダに条件に見合った日付が入るかどうか Response.Write "<td width=50 height=50 align=left valign=top>" '-------祝日表示(元旦 成人の日・・・・天皇誕生日)--------------------------------------------------------------------------------------------------------------------- If DateSerial(iyear,imonth,idate)= DateSerial(iyear,1,1) Then Response.Write "<font color=red>"& idate &"<font size = 2>"&"元旦"&"</font>" & "</font>" Else IF DateSerial(iyear,imonth,idate)= DateSerial(iyear,1,15-Weekday(Dateserial(iyear,1,1)-2)) Then Response.Write "<font color=red>"& idate & "<font size = 2>"&"成人の日"&"</font>" & "</font>" Else If DateSerial(iyear,imonth,idate)= DateSerial(iyear,2,11) Then Response.Write "<font color=red>"& idate & "<font size = 2>" & "建国記念日 " & "</font>" & "</font>" Else If Dateserial(iyear,imonth,idate)=DateSerial(iyear, 3, (20.8431 + 0.242194 * (iyear - 1980)) - ((iyear - 1980) / 4)) Then Response.Write "<font color=red>"& idate & "<font size = 2>"&"春分の日"&"</font>" & "</font>" Else If DateSerial(iyear,imonth,idate)= DateSerial(iyear,4,29) Then Response.Write "<font color=red>"& idate & "<font size = 2>"&"昭和の日"&"</font>" & "</font>" Else If Dateserial(iyear,imonth,idate)= Dateserial(iyear,5,3) Then Response.Write "<font color=red>"& idate & "<font size = 2>"&"憲法記念日"&"</font>" & "</font>" Else If Dateserial(iyear,imonth,idate)= Dateserial(iyear,5,4) Then Response.Write "<font color=red>"& idate & "<font size = 2>"&"国民の日"&"</font>" & "</font>" Else If Dateserial(iyear,imonth,idate)= Dateserial(iyear,5,5) Then Response.Write "<font color=red>"& idate & "<font size = 2>"&"こどもの日"&"</font>" & "</font>" Else If Dateserial(iyear,imonth,idate) = Dateserial(iyear,7,20-Weekday(Dateserial(iyear,7,1)-4)) Then Response.Write "<font color=red>"& idate & "<font size = 2>"&"海の日"&"</font>" & "</font>" Else If Dateserial(iyear,imonth,idate) = Dateserial(iyear,9,15-Weekday(Dateserial(iyear,9,1))) Then Response.Write "<font color=red>"& idate & "<font size = 2>"&"敬老の日"&"</font>" & "</font>" Else If Dateserial(iyear,imonth,idate) =DateSerial(iyear, 9, (23.3488 + 0.242194 * (iyear - 1980)) - ((iyear - 1980) / 4)) Then Response.Write "<font color=red>"& idate & "<font size = 2>"&"秋分の日"&"</font>" & "</font>" Else If Dateserial(iyear,imonth,idate) = Dateserial(iyear,10,10-Weekday(Dateserial(iyear,10,1)-7)) Then Response.Write "<font color=red>"& idate & "<font size = 2>"&"体育の日"&"</font>" & "</font>" Else If Dateserial(iyear,imonth,idate)= Dateserial(iyear,11,3) Then Response.Write "<font color=red>"& idate & "<font size = 2>"&"文化の日"&"</font>" & "</font>" Else If Dateserial(iyear,imonth,idate)= Dateserial(iyear,11,23) Then Response.Write "<font color=red>"& idate & "<font size = 2>"&"勤労感謝の日"&"</font>" & "</font>" Else If Dateserial(iyear,imonth,idate)= Dateserial(iyear,12,23) Then Response.Write "<font color=red>"& idate & "<font size = 2>"&"天皇誕生日"&"</font>" & "</font>" '------------------------------------------------------------------------------------------------------------------------------祝日設定------------------- '本日の日付の桃色表示 Else If Date() = Dateserial(iyear,imonth,idate) Then Response.Write "<font color=ff00ff>" & idate &"<font size = 2>"& "今日"&"</font>" & "</font>" '日曜は赤色表示 Else If (Weekday(j) = 7) Then Response.Write "<font color=red>" & idate & "</font>" '土曜は青色表示 Else If (Weekday(j) = 6) Then Response.Write "<font color=blue>" & idate & "</font>" 'その他、黒色表示 Else Response.Write "<font color=black>" & idate & "</font>" End If End if End If End If End If End If End If End If End If End If End if End If End If End IF End If End If End If End If Response.Write "</td>" Else Response.Write "<td width=50 height=50 align=center>" & "" Response.Write "</td>" End If idate = idate + 1 If idate > ilastday Then ' 表示日が最終日を越えた場合 Exit For End If Next Response.Write "</tr>" If idate > ilastday Then ' 表示日が最終日を越えた場合 Exit For End If Next %> </table> 今日は <% = CDate(now()) %> <form method = "post" action = "calender.asp"> <input Type = "text" name = "year" size = "8" value = "<% response.write year(now) %>">年 <input Type = "text" name = "month" size = "4" value = "<% response.write month(now) %>">月 <input Type = "submit" value = "カレンダ表示" > <input Type = "reset" value = "リセット"> </form> </BODY> </HTML> |
![]() ![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
TreeBBS For ASP V.0.1.3 |