出来るのだASP Q&A掲示板(過去LOG)
訪問数 52046
昨日 889
今日 776 【PR】 パソコン入門からIT専門書まで幅広く取り揃えています。セブン-イレブン受取り手数料無料のセブンアンドワイ。 |
![]() ![]() ![]() ![]() ![]() |
![]() ![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
[5564] カレンダ作成についてわからないことがあるのですが・・・ |
投稿者:さとしさん 2006/01/10 17:38:09 |
こんにちは。掲示板でちょっと力を借りようと来ました。 aspを使って汎用的なカレンダを作っています。inputボタンを作成して ex)9999年01月というのを取り出せるようにしたいのですが、今、壁にぶちあたってます。 たぶん月日の引数の個所が悪いと思うんですが、どんな風に引き渡したらいいのか教えてもらえるでしょうか。よろしくお願いします。 |
[5565] 初心者でめちゃくちゃですがよろしくお願いします |
投稿者:さとしさん 2006/01/10 17:40:44 |
<%@ language=vbscript %> <% option explicit %> <html> <head> <title>カレンダー表示</title> </head> <body bgcolor="#f5f5f5"> <% dim saisyuubi dim hiduke dim Thyo dim Yhyo dim iyear dim imonth iyear = year(now) imonth= month(now) hiduke = 1-weekday(dateserial(iyear,imonth,1))+1 saisyuubi = day(dateserial(iyear,imonth+1,1-1)) response.write "西暦" & iyear & "年" & imonth & "月" &_ "<table border=0>" for Yhyo = 0 to 6 response.write "<td width=50 height=25 align=center>" if (weekday(Yhyo) = 7) then response.write "<font color=red>" end if if (weekday(Yhyo) = 6) then response.write "<font color=blue>" end if response.write weekdayname(Yhyo+1,true) response.write "</td>" next for Thyo = 0 to 5 response.write "<tr>" for Yhyo = 0 to 6 if hiduke > 0 and hiduke <= saisyuubi then response.write "<td width=50 height=50 align=center>" if Yhyo = 0 then response.write "<font color=red>" & hiduke & "</font>" end if if Yhyo = 6 then response.write "<font color=blue>" & hiduke & "</font>" end if if Yhyo = 1 then response.write "<font color=black>" & hiduke & "</font>" end if if Yhyo = 2 then response.write "<font color=black>" & hiduke & "</font>" end if if Yhyo = 3 then response.write "<font color=black>" & hiduke & "</font>" end if if Yhyo = 4 then response.write "<font color=black>" & hiduke & "</font>" end if if Yhyo = 5 then response.write "<font color=black>" & hiduke & "</font>" end if response.write "</td>" else response.write "<td width=50 height=50 align=center>" & "" response.write "</td>" end if hiduke = hiduke + 1 if hiduke > saisyuubi then exit for end if next response.write "</tr>" if hiduke > saisyuubi then exit for end if next response.write "</table>" response.write "今日は" & CDate(now()) %> <form method = "post" action = "test/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 = "カレンダ表示" > </body> </html> |
[5566] Re:初心者でめちゃくちゃですがよろしくお願いします |
投稿者:ビギナーズラックさん 2006/01/10 22:11:55 |
ええっと何をされたいのか今ひとつぴんとこないので 具体的に何をどうしたいのか詳しく書いてくれれば 答えやすいのではないかと思います。 カレンダー自体のサンプルは巷にあふれていますから カレンダー表示自体は初心者でも比較的簡単にできるでしょうが... |
[5568] Re:初心者でめちゃくちゃですがよろしくお願いします |
投稿者:さとしさん 2006/01/11 10:02:37 |
> ええっと何をされたいのか今ひとつぴんとこないので > 具体的に何をどうしたいのか詳しく書いてくれれば > 答えやすいのではないかと思います。 > カレンダー自体のサンプルは巷にあふれていますから > カレンダー表示自体は初心者でも比較的簡単にできるでしょうが... > ビギナーズラックさん、回答ありがとうございました。 ただいま、input文で年月を入力すると、その年月に該当するカレンダが表示するようなものを作っています。現在、悩んでいるところは、年月を入力しても、該当するカレンダが表示されていないことです。ちなみに2006年1月のカレンダは表示されるようになっています。(現在のところですが・・・)これで、2006年2月が表示されるようになったら大成功なのですが・・・・すみません、たぶん、ソースの一番上の方と 下の方の引数の受け渡しがおかしいと思うんですが、よろしければ、ご指摘願いますでしょうか。よろしくお願いします。 |
[5567] Re:初心者でめちゃくちゃですがよろしくお願いします |
投稿者:Lightningさん 2006/01/11 8:39:13 |
ソース上の改善点はいろいろありますが、質問への回答は if request("year")="" then iyear = year(now) else iyear =request("year") end if こういうことだと思いますが・・・ なお、メソッドがpost固定で決まっているのならrequestはrequest.formを使ったほうがいいです。 request.formはformのmethodがpostの場合に使います。 request.form("year")とかって感じに。 で、改善点ですが・・・ if Yhyo = 0 then response.write "<font color=red>" & hiduke & "</font>" end if if Yhyo = 6 then response.write "<font color=blue>" & hiduke & "</font>" end if if Yhyo = 1 then response.write "<font color=black>" & hiduke & "</font>" end if if Yhyo = 2 then response.write "<font color=black>" & hiduke & "</font>" end if if Yhyo = 3 then response.write "<font color=black>" & hiduke & "</font>" end if if Yhyo = 4 then response.write "<font color=black>" & hiduke & "</font>" end if if Yhyo = 5 then response.write "<font color=black>" & hiduke & "</font>" end if は select case Yhyo case 0: response.write "略" case 6: response.write "略" case else: response.write "略" end select って感じにしてしまうとか、いろいろ考えられると思います。 #もしかしたらJSなどのswitchの書式と混ざっている可能性があるのでselectCaseに関しては使用前に確認してください。 |
[5569] 私ならこんな感じのソースにするかな? |
投稿者:Lightningさん 2006/01/11 10:04:30 |
<%@ 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> というサンプルソース。 いじってて思ったんですが、tableタグの内部でのセル数が統一されてなかったり、タグが閉じてない点が多々あったり。 borderは作成段階では0にせず、tableの状況が見えるようにしたほうがいいです。 あと、ASPは関係ない点ですが、tableなどはいちいち改行、tabを入れてインデントを意識的にソースに現れるようにしておくとミスを発見しやすくなるのでお勧めです。 #めんどくさいけどね。 |
[5573] Re:私ならこんな感じのソースにするかな? |
投稿者:Lightningさん 2006/01/11 10:35:42 |
> <%@ 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の中にあるか? です、って年の方といっしょやん!(笑 |
[5576] Re:私ならこんな感じのソースにするかな? |
投稿者:さとしさん 2006/01/11 13:44:22 |
> > <%@ 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の間の数値ということで解釈していいんでしょうか? |
[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の間の数値ということで解釈していいんでしょうか? |
[5578] Re:ソースファイルの書き方が下手くそですが・・・ |
投稿者:ビギナーズラックさん 2006/01/11 23:37:16 |
> お世話になっています。私のプログラムは非常に読みづらいと先輩に言われました。実は、初めてaspでプログラムというのを組んだのですが、具体的にどの変が読みづらいでしょうか?何かプログラム一部を簡略化するのか、はたまた改行などをして読みやすくするのか、変数の宣言の仕方が下手だとか、技術面もろもろといろいろ中傷願います。 多分そんなに読みにくくないですよ?(^^ 今回のように比較的シンプルなコードでは書き手によってあまり差が出ないので 素直に慣例に従って書けば読みやすくなるでしょうし 普通はしない=効率が悪いコードは嫌われるので、読みにくいと言われると思います。 基本的な慣例はVBの初心者用の解説書なんかにたくさん載っています。 コード中でわざわざvbcrlfを入れるのは、あくまでもデバッグの効率を考えた場合で ブラウザ出力の点からいくと非効率ですし、第三者がVBソースを見るときにも醜くなること請け合いです。 もちろん私は汚いHTMLソースになると恥ずかしいということと ガリガリ書いたVBソースを一発動作させるほど気合いを入れて書いてないという理由で改行コードは入れてますが(w それと変数の宣言云々に下手とか正直どーでもいいと思うのですが VBでもある程度、推奨事項があります。 これはVBの本に載ってます。 #ASPの本はVBSなどの言語の基本なんかは無視してかかれていることが多いので基本的な慣例はVBの書籍の方がいいかもしれませんね。 Dim iMonthのiはintのiでしょうから統一するなら saisyuubiやhidukeもiSaisyuubi、iHidukeでOKかと。 できれば何も付いていない変数saisyuubiなどは、ぱっと見て何かわかりませんので intSaisyuubiとかiSaisyuubiとかにしたほうがすっきりします。 私ならintLastDayにすると思います。 もちろんこれも自分でわかりやすいように決めればいい話ですけど どうせやるなら変数は自分で意味のわかる英単語の組み合わせがいいと思います。 正直saisyuubiっていう変数があるだけで私は読みにくいって思ってしまいます(^^; |
[5579] Re:ソースファイルの書き方が下手くそですが・・・ |
投稿者:さとしさん 2006/01/12 9:08:48 |
ビギナーズラックさん、回答ありがとうございます 大変参考になりました。正直、VisualBasicをやったことがないため、基本を抑えてないのは確かです。VBの本少し読みあさっていきたいと思います。変数のアドバイスどうもありがとうございました。さっそく、参考にさせていただきます。失礼しました。 > > お世話になっています。私のプログラムは非常に読みづらいと先輩に言われました。実は、初めてaspでプログラムというのを組んだのですが、具体的にどの変が読みづらいでしょうか?何かプログラム一部を簡略化するのか、はたまた改行などをして読みやすくするのか、変数の宣言の仕方が下手だとか、技術面もろもろといろいろ中傷願います。 > > 多分そんなに読みにくくないですよ?(^^ > > 今回のように比較的シンプルなコードでは書き手によってあまり差が出ないので > 素直に慣例に従って書けば読みやすくなるでしょうし > 普通はしない=効率が悪いコードは嫌われるので、読みにくいと言われると思います。 > 基本的な慣例はVBの初心者用の解説書なんかにたくさん載っています。 > > コード中でわざわざvbcrlfを入れるのは、あくまでもデバッグの効率を考えた場合で > ブラウザ出力の点からいくと非効率ですし、第三者がVBソースを見るときにも醜くなること請け合いです。 > もちろん私は汚いHTMLソースになると恥ずかしいということと > ガリガリ書いたVBソースを一発動作させるほど気合いを入れて書いてないという理由で改行コードは入れてますが(w > > それと変数の宣言云々に下手とか正直どーでもいいと思うのですが > VBでもある程度、推奨事項があります。 > これはVBの本に載ってます。 > #ASPの本はVBSなどの言語の基本なんかは無視してかかれていることが多いので基本的な慣例はVBの書籍の方がいいかもしれませんね。 > > Dim iMonthのiはintのiでしょうから統一するなら > saisyuubiやhidukeもiSaisyuubi、iHidukeでOKかと。 > できれば何も付いていない変数saisyuubiなどは、ぱっと見て何かわかりませんので > intSaisyuubiとかiSaisyuubiとかにしたほうがすっきりします。 > 私ならintLastDayにすると思います。 > もちろんこれも自分でわかりやすいように決めればいい話ですけど > どうせやるなら変数は自分で意味のわかる英単語の組み合わせがいいと思います。 > 正直saisyuubiっていう変数があるだけで私は読みにくいって思ってしまいます(^^; |
[5580] Re:ソースファイルの書き方が下手くそですが・・・ |
投稿者:Lightningさん 2006/01/12 9:39:48 |
> お世話になっています。私のプログラムは非常に読みづらいと先輩に言われました。実は、初めてaspでプログラムというのを組んだのですが、具体的にどの変が読みづらいでしょうか?何かプログラム一部を簡略化するのか、はたまた改行などをして読みやすくするのか、変数の宣言の仕方が下手だとか、技術面もろもろといろいろ中傷願います。 > > > お世話になっています 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の間の数値ということで解釈していいんでしょうか? 解釈はそれであってます。 入力数値の監視機構が存在しないとバッファオーバーフロー攻撃が可能になったりと大変なので入力値の監視は必ずしてください。 読みにくい部分、ですが、何度か組めばローマ字は駄目だとわかると思います。 母音が被るのでよく間違えるし、今回の例だと「saisyuubi」なんかは「saisyubi」と書き、実行時に何が違うのかわからない落とし穴にはまる可能性があります。 あとは、タグの書き方とか気になったかも。 閉じてないとか多々あったし。 あと、入れ子構造とかが多発しているのも気になった。 仕方ないとはいえ、なるべく避けたほうが良いです。 あと、カウンタに使う変数は正規教育を受けた場合、i,jあたりかn,mあたりに落ち着きます。 これは結構気になる人がいたりするので注意です。 あとはー エディタによりますが、コメントの場合は色を変える設定をしておけば、ifごとにどういう分岐かのコメントをつけておくと目立ったりとか。 掲示板書き込み時に崩壊したのだと思いますが、意識してインデント(行頭にスペースをつけることで入れ子などの構造を見えるようにする手法)をするとかしてみてください。 とかかなあ・・・ 私もあんまりきれーなソースじゃないからなあ・・・ #vbcrlf(改行コード)とvbtab(タブ)は普通はいらないですが、table構造やformを書くときは意識して入れるとHTMLソースを確認するときに便利ですよ〜 |
[5581] Re:ソースファイルの書き方が下手くそですが・・・ |
投稿者:さとしさん 2006/01/12 13:57:49 |
> > お世話になっています。私のプログラムは非常に読みづらいと先輩に言われました。実は、初めてaspでプログラムというのを組んだのですが、具体的にどの変が読みづらいでしょうか?何かプログラム一部を簡略化するのか、はたまた改行などをして読みやすくするのか、変数の宣言の仕方が下手だとか、技術面もろもろといろいろ中傷願います。 > > > > > > お世話になっています 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の間の数値ということで解釈していいんでしょうか? > 解釈はそれであってます。 > 入力数値の監視機構が存在しないとバッファオーバーフロー攻撃が可能になったりと大変なので入力値の監視は必ずしてください。 > > 読みにくい部分、ですが、何度か組めばローマ字は駄目だとわかると思います。 > 母音が被るのでよく間違えるし、今回の例だと「saisyuubi」なんかは「saisyubi」と書き、実行時に何が違うのかわからない落とし穴にはまる可能性があります。 > > > あとは、タグの書き方とか気になったかも。 > 閉じてないとか多々あったし。 > あと、入れ子構造とかが多発しているのも気になった。 > 仕方ないとはいえ、なるべく避けたほうが良いです。 > > あと、カウンタに使う変数は正規教育を受けた場合、i,jあたりかn,mあたりに落ち着きます。 > これは結構気になる人がいたりするので注意です。 > > あとはー > エディタによりますが、コメントの場合は色を変える設定をしておけば、ifごとにどういう分岐かのコメントをつけておくと目立ったりとか。 > 掲示板書き込み時に崩壊したのだと思いますが、意識してインデント(行頭にスペースをつけることで入れ子などの構造を見えるようにする手法)をするとかしてみてください。 > > とかかなあ・・・ > 私もあんまりきれーなソースじゃないからなあ・・・ > #vbcrlf(改行コード)とvbtab(タブ)は普通はいらないですが、table構造やformを書くときは意識して入れるとHTMLソースを確認するときに便利ですよ〜 Lightningさん いつもお世話になっています。さっそく、変数のローマ字はやめて英語にしました。エディタはTeraPadを使ってコメント部分は色つきにしました。タグの書き方はいろいろとプログラムを見ながら勉強しようと思います。あと、カレンダーはちゃんと動的に表示されました。ありがとうございました。(まぁここの掲示板の方々に最後はやってもらったようなものですが・・・^^;) おっとぉ、入力数値の監視機構ですね!調べてやってみます! |
[5582] Re:ソースファイルの書き方が下手くそですが・・・ |
投稿者:Lightningさん 2006/01/12 15:41:35 |
お疲れ様です〜 うまく動いてよかったですね〜 あと、書き忘れてましたが、全文引用は却下で。 むっちゃみにくいっす |
[5570] Re:初心者でめちゃくちゃですがよろしくお願いします |
投稿者:さとしさん 2006/01/11 10:08:08 |
> ソース上の改善点はいろいろありますが、質問への回答は > if request("year")="" then > iyear = year(now) > else > iyear =request("year") > end if > こういうことだと思いますが・・・ > なお、メソッドがpost固定で決まっているのならrequestはrequest.formを使ったほうがいいです。 > > request.formはformのmethodがpostの場合に使います。 > request.form("year")とかって感じに。 > > で、改善点ですが・・・ > > if Yhyo = 0 then > response.write "<font color=red>" & hiduke & "</font>" > end if > if Yhyo = 6 then > response.write "<font color=blue>" & hiduke & "</font>" > end if > if Yhyo = 1 then > response.write "<font color=black>" & hiduke & "</font>" > end if > if Yhyo = 2 then > response.write "<font color=black>" & hiduke & "</font>" > end if > if Yhyo = 3 then > response.write "<font color=black>" & hiduke & "</font>" > end if > if Yhyo = 4 then > response.write "<font color=black>" & hiduke & "</font>" > end if > if Yhyo = 5 then > response.write "<font color=black>" & hiduke & "</font>" > end if > は > select case Yhyo > case 0: > response.write "略" > case 6: > response.write "略" > case else: > response.write "略" > end select > って感じにしてしまうとか、いろいろ考えられると思います。 > #もしかしたらJSなどのswitchの書式と混ざっている可能性があるのでselectCaseに関しては使用前に確認してください。 Lightningさん回答ありがとうございました。 select文ですっきとさせました。実際にrequest.form("year")とrequest("month")というのを宣言の上に付け足したのですが、特になにも起こりませんでした。すごい初歩的かもしれませんが、もう一歩ご指摘願いますでしょうか。よろしくお願いします。失礼しました。 <%@ language=vbscript %> <% option explicit %> <html> <head> <title>カレンダー表示</title> </head> <body bgcolor="#f5f5f5"> <% '================================ '入力データの取得 '================================ request.form("year") request.form("month") dim saisyuubi dim hiduke dim Thyo dim Yhyo dim iyear dim imonth iyear = year(now) imonth= month(now) '================================ '日付の週の一日目と月の末、作成 '================================ hiduke = 1-weekday(dateserial(iyear,imonth,1))+1 saisyuubi = day(dateserial(iyear,imonth+1,1-1)) response.write "西暦" & iyear & "年" & imonth & "月" &_ "<table border=0>" for Yhyo = 0 to 6 response.write "<td width=50 height=25 align=center>" if (weekday(Yhyo) = 7) then response.write "<font color=red>" end if if (weekday(Yhyo) = 6) then response.write "<font color=blue>" end if response.write weekdayname(Yhyo+1,true) response.write "</td>" next '================================= 'カレンダ本体、1〜7日で折り返して '作成。 '================================= for Thyo = 0 to 5 response.write "<tr>" for Yhyo = 0 to 6 if hiduke > 0 and hiduke <= saisyuubi then response.write "<td width=50 height=50 align=center>" 'select文ですっきりと select case Yhyo case 0 response.write "<font color=red>" & hiduke & "</font>" case 6 response.write "<font color=blue>" & hiduke & "</font>" case else response.write "<font color=black>" & hiduke & "</font>" end select response.write "</td>" else response.write "<td width=50 height=50 align=center>" & "" response.write "</td>" end if hiduke = hiduke + 1 if hiduke > saisyuubi then exit for end if next response.write "</tr>" if hiduke > saisyuubi then exit for end if next response.write "</table>" response.write "今日は" & 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 = "カレンダ表示" > </body> </html> |
[5571] Re:初心者でめちゃくちゃですがよろしくお願いします |
投稿者:Lightningさん 2006/01/11 10:14:00 |
説明不足でしたね、すいません。 formからsubmitした場合、formのactionで示されたものに対し、データが送られるのですが、送られたデータを受け取る必要があります。 ASPの場合、送られたデータのmethodがPOSTの場合はRequest.form(前のformのアイテムのname)で取得できます。 #methodがGETの場合はURLから抜き出してみたりとかRequest.QueryString(Formでのname)で取得できます。 だから <form action="./test1.asp" method="post"> <input type="text" name="t1"> <input type="Submit"> </form> の場合、 test1.aspで formText = Request.Form("t1") とするとformTextにt1に書いた内容が格納されるわけです。 |
[5572] Re:初心者でめちゃくちゃですがよろしくお願いします |
投稿者:さとしさん 2006/01/11 10:20:42 |
> 説明不足でしたね、すいません。 > > formからsubmitした場合、formのactionで示されたものに対し、データが送られるのですが、送られたデータを受け取る必要があります。 > > ASPの場合、送られたデータのmethodがPOSTの場合はRequest.form(前のformのアイテムのname)で取得できます。 > #methodがGETの場合はURLから抜き出してみたりとかRequest.QueryString(Formでのname)で取得できます。 > > だから > <form action="./test1.asp" method="post"> > <input type="text" name="t1"> > <input type="Submit"> > </form> > の場合、 > test1.aspで > formText = Request.Form("t1") > とするとformTextにt1に書いた内容が格納されるわけです。 丁寧な説明ありがとうございました。Lightningさんのソースをじっくりにらめっこしながら、あらたな構文も発見したので調べながらやってみようと思います。また質問等することがございますが、その時は未熟者ですがよろしくお願いします。 |
[5574] Re:初心者でめちゃくちゃですがよろしくお願いします |
投稿者:ビギナーズラックさん 2006/01/11 13:16:24 |
> formからsubmitした場合、formのactionで示されたものに対し、データが送られるのですが、送られたデータを受け取る必要があります。 完全に想定外でした(^^; |
[5575] Re:初心者でめちゃくちゃですがよろしくお願いします |
投稿者:さとしさん 2006/01/11 13:36:10 |
> > formからsubmitした場合、formのactionで示されたものに対し、データが送られるのですが、送られたデータを受け取る必要があります。 > > 完全に想定外でした(^^; > > ビギナーズラックさん どうもお手数かけました^^; |
[5583] calender仕上がりソースファイル 皆様ありがとうございました また勉強してきます |
投稿者:さとしさん 2006/01/12 15:56:16 |
<%@ language=vbscript %> <% Option Explicit %> <html> <head> <title>カレンダー表示</title> </head> <body bgcolor="#f5f5f5"> <% Dim ilastday Dim idate Dim Ttable Dim Ytable Dim iyear Dim imonth Const MINI_YEAR = 0 Const MAX_YEAR = 9999 Const MINI_MONTH = 1 Const MAX_MONTH = 12 'formからのpostがある場合と無い場合の切り分け If Request.Form("year") = "" Then '入力データの取得 "年" iyear = year(now) Else iyear = Request.Form("year") End if If Isnumeric(iyear) Then '入力値が整数であるか、また入力データが0〜9999であるか条件分岐 If MINI_YEAR > iyear and MAX_YEAR < iyear Then iyear = year(now) End if else iyear = Request.Form("year") End if If Request.Form("month") = "" Then '入力データの取得 "月" imonth = month(now) Else imonth = Request.Form("month") End if If isnumeric(imonth) Then '入力値が整数であるか、また入力データが1〜12であるか条件分岐 If MINI_MONTH >= imonth and MAX_MONTH <= imonth Then imonth = month(now) End if else imonth = month(now) End if 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=0>" 'テーブルの作成 Response.Write "<tr>" For Ytable = 0 To 6 '曜日欄の作成 Weekdaynameで曜日を返していく response.write "<td width=50 height=25 align=center>" If (Weekday(Ytable) = 7) Then Response.Write "<font color=red>" End if If (Weekday(Ytable) = 6) Then Response.Write "<font color=blue>" End If Response.Write Weekdayname(Ytable+1,true) Response.Write "</td>" Next Response.Write "</tr>" For Ttable = 0 To 5 'カレンダ、月の1日目から月の最終日の表示 Response.Write "<tr>" For Ytable = 0 To 6 If idate > 0 and idate <= ilastday Then 'カレンダに条件に見合った日付が入るかどうか Response.Write "<td width=50 height=50 align=center>" Select Case Ytable Case 0 Response.Write "<font color=red>" & idate & "</font>" Case 6 Response.Write "<font color=blue>" & idate & "</font>" Case Else Response.Write "<font color=black>" & idate & "</font>" End Select 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 Response.Write "</table>" Response.Write "今日は" & 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 = "カレンダ表示" > <!-- フォームでsubmitしたらrequest.formに投げかける --> </body> </html> |
TreeBBS For ASP V.0.1.3 |