出来るのだASP Q&A掲示板(過去LOG)
訪問数 52046
昨日 889
今日 776 【PR】 パソコン入門からIT専門書まで幅広く取り揃えています。セブン-イレブン受取り手数料無料のセブンアンドワイ。 |
![]() ![]() ![]() ![]() ![]() |
[5577] ソースファイルの書き方が下手くそですが・・・ |
投稿者:さとしさん 2006/01/11 18:11:18 |
お世話になっています。私のプログラムは非常に読みづらいと先輩に言われました。実は、初めてaspでプログラムというのを組んだのですが、具体的にどの変が読みづらいでしょうか?何かプログラム一部を簡略化するのか、はたまた改行などをして読みやすくするのか、変数の宣言の仕方が下手だとか、技術面もろもろといろいろ中傷願います。 > > > <%@ language=vbscript %> > > > <% option explicit %> > > > <html> > > > <head> > > > <title>カレンダー表示</title> > > > </head> > > > <body bgcolor="#f5f5f5"> > > > <% > > > > > > dim saisyuubi > > > dim hiduke > > > dim iyear > > > dim imonth > > > dim YColor(6) > > > dim i > > > > > > '曜日色初期化 > > > YColor(0) = "red" > > > YColor(6) = "blue" > > > for i = 1 to 5 > > > YColor(i) = "black" > > > next > > > > > > 'formからのPOSTがある場合と無い場合を切り分け > > > if request.form("year")="" then > > > iyear = year(now) > > > else > > > iyear =request.form("year") > > > end if > > > if request.form("month")="" then > > > imonth = month(now) > > > else > > > imonth =request.form("month") > > > end if > > > > > > hiduke = 1-weekday(dateserial(iyear,imonth,1))+1 > > > saisyuubi = day(dateserial(iyear,imonth+1,1-1)) > > > > > > > > > response.write "<div>西暦" & iyear & "年" & imonth & "月</div>" & vbcrlf > > > response.write "<table border=1>" & vbcrlf > > > response.write vbtab & "<tr>" & vbcrlf > > > for i = 0 to 6 > > > response.write vbtab & vbtab & "<th width=50 height=25 align=center><font color=" & YColor(i) & ">" > > > response.write weekdayname(i+1,true) & "</font></th>" & vbcrlf > > > next > > > response.write vbtab & "</tr>" & vbcrlf > > > for i = hiduke to saisyuubi + 7- weekday(dateserial(iyear,imonth,saisyuubi)) > > > if weekday(dateserial(iyear,imonth,i)) = 1 then > > > response.write vbtab & "<tr>" & vbcrlf > > > end if > > > if i > 0 and i <= saisyuubi then > > > response.write vbtab & vbtab & "<td width=""50"" height=""50"" align=""center"">" > > > response.write "<font color=" & YColor(weekday(dateserial(iyear,imonth,i)) - 1) & ">" & i & "</font>" > > > response.write "</td>" & vbcrlf > > > else > > > response.write vbtab & vbtab & "<td width=50 height=50 align=center>-</td>" & vbcrlf > > > end if > > > if weekday(dateserial(iyear,imonth,i)) = 7 then > > > response.write vbtab & "</tr>" & vbcrlf > > > end if > > > next > > > > > > response.write "</table>" > > > > > > response.write "今日は" & CDate(now()) > > > > > > %> > > > <form method = "post" action = "./test.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 = "カレンダ表示" > > > > </form> > > > </body> > > > </html> > > 追加説明、formのactionをみればわかりますが、ファイル名をtest.aspとしてあります。 > > また、入力された文字のサニタイズをしていないので、request.formで受け取った文字列が年、月として使用可能なものであるかどうかの判定を追加してください。 > > 例 > > if request.form("year")="" then > > iyear = year(now) > > else > > iyear =request.form("year") > > if isnumeric(iyear) then > > if 1970 > iyear or 2070 < iyear then > > iyear = year(now) > > end if > > else > > iyear = year(now) > > end if > > とか > > > > 月の方はもっと単純で > > 受け取った値が整数であるか? > > 整数であれば、1〜12の中にあるか? > > です、って年の方といっしょやん!(笑 > > > お世話になっています Ligthningさん > if request.form("year") = "" then > iyear = year(now) > else > iyear = request.form("year") > end if > if isnumeric(iyear) then > if 0 > iyear or 9999 < iyear then > iyear = year(now) > end if > else > iyear = year(now) > end if > ここの文なのですが、入力するところが、空欄ならば現在の年を表す、もし何か数値が入ってればその数値をiyearに返す。さらにその数値は > 整数であって、0〜9999の間の数値ということで解釈していいんでしょうか? |
![]() ![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
TreeBBS For ASP V.0.1.3 |