| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 608 人关注过本帖
标题:怎样用vbscript 写个日历
只看楼主 加入收藏
mejiang
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-6-15
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
怎样用vbscript 写个日历
  怎样用vbscript 写个日历 ,我要代码加注释。
搜索更多相关主题的帖子: vbscript 日历 
2010-06-15 00:41
gupiao175
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:40
帖 子:1787
专家分:7527
注 册:2007-6-27
收藏
得分:20 
程序代码:
<style type="text/css">
<!--
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style>
<%
y=request.querystring("y")
m=request.querystring("m")
d=request.querystring("d")
if y="" then
y=year(date)
m=month(date)
d=day(date)
end if
call blogdate(y,m,d)
'=====================以年月日为参数的显示==============================================
sub blogdate(y,m,d) '
str1="&nbsp;&nbsp;&nbsp;当前的日期是"&y&""&m&""&d&"日&nbsp;&nbsp;&nbsp;" '得到当前日期的年月日
nowdate=y&"-"&m&"-"&d
lastdate=dateadd("m",-1,nowdate)
lasty=year(lastdate)
lastm=month(lastdate)
nextdate=dateadd("m",1,nowdate)
nexty=year(nextdate)
nextm=month(nextdate)
str1=str1&"<a href="&request.servervariables("path_info")&"?y="&lasty&"&m="&lastm&"&d=1"&">上一月</a>&nbsp;"
str1=str1&"<a href="&request.servervariables("path_info")&"?y="&nexty&"&m="&nextm&"&d=1"&">下一月</a>&nbsp;"
str1=str1&"<a href="&request.servervariables("path_info")&">返回今日</a>"
response.write str1
thismonth=y&"-"&m&"-1" '当前月的第一天
nextmonth=dateadd("m",1,thismonth) '下个月的第一天
num=datediff("d",thismonth,nextmonth) '当前月的天数
firstday=weekday(thismonth)-1 '得到当前月第一天的星期
'call displaydate(firstday,num)
Response.Write "<table border=1 width=""40%"" style=""border-collapse:collapse"">" & vbCrlf
Response.Write "<tr>" & vbCrlf
Response.Write "<td align=""center"">星期日</td>" & vbCrlf
Response.Write "<td align=""center"">星期一</td>" & vbCrlf
Response.Write "<td align=""center"">星期二</td>" & vbCrlf
Response.Write "<td align=""center"">星期三</td>" & vbCrlf
Response.Write "<td align=""center"">星期四</td>" & vbCrlf
Response.Write "<td align=""center"">星期五</td>" & vbCrlf
Response.Write "<td align=""center"">星期六</td>" & vbCrlf
Response.Write "</tr>" & vbCrlf
'需要参数:当前月第一天的星期firstday,当前月的天数 num
for n=1 to 6
response.write "<tr>"
for i=1 to 7
thisday=0
if i>firstday then thisday=i-firstday
if n>1 then thisday=7*(n-1)+i-firstday
if thisday>num then thisday=0
if thisday=0 then
display="&nbsp;"
else
display="<a href="&request.servervariables("path_info")&"?y="&y&"&m="&m&"&d="&thisday&">"&thisday&"</a>"
end if
response.write "<td align=""center"">"&display&"</td>"
next
if n=5 and (thisday=num or thisday=0) then n=n+1
response.write "</tr>"
next
Response.Write "</table>" & vbCrlf
end sub
'===================================================================
%>

网上找的,先自己看分析下,有看不明白的再说!

Q:1428196631,百度:开发地 即可找到我,有事请留言!
2010-06-18 15:48
gupiao175
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:40
帖 子:1787
专家分:7527
注 册:2007-6-27
收藏
得分:0 
上面的代码虽然是基于VB脚本的,但是却必须保存为ASP,然后在IIS下才能执行!

这里再提供一个VB脚本写的能在客户端直接执行的日历,保存为HTML即可!不过实际中一般人都不用VB写的,而是JS写的!
程序代码:
<!--
    自制 vbscript 日歷
    可以點擊頂端的“年”,“月”以及

 “ <<” “>> ”進行日期選取 “
-->
<html>
    <head>
        <style>
            .Weekend{color:red; font-family:Verdana,Arial,Helvetica,sans-serif; text-align:center; cursor:hand; border-left:solid 1px #c0c0c0; border-right:solid 1px #c0c0c0; border-top:solid 1px #c0c0c0; border-bottom:solid 1px #c0c0c0;}
            .Today{background-color:#cccccc; color:#006666; font-family:Verdana,Arial,Helvetica,sans-serif; font-weight:bold; text-align:center; cursor:hand; border-right:solid 1px #c0c0c0; border-top:solid 1px #c0c0c0; border-bottom:solid 1px #c0c0c0;}
            .Day{color:#006666; font-family:Verdana,Arial,Helvetica,sans-serif; text-align:center; cursor:hand; border-left:solid 1px #c0c0c0; border-right:solid 1px #c0c0c0; border-top:solid 1px #c0c0c0; border-bottom:solid 1px #c0c0c0;}
            .Date{text-align:center; color:#006666; font-family:Verdana,Arial,Helvetica,sans-serif; background-color:#cccccc; border-left:solid 1px #c0c0c0; border-right:solid 1px #c0c0c0; border-top:solid 1px #c0c0c0; border-bottom:solid 1px #c0c0c0;}
            .OtherMonth{text-align:center; font-family:Verdana,Arial,Helvetica,sans-serif; border-left:solid 1px #c0c0c0; border-right:solid 1px #c0c0c0; border-top:solid 1px #c0c0c0; border-bottom:solid 1px #c0c0c0;}
          
            .YearMonth{font-weight:normal; color:#006666; cursor:hand; font-family: Verdana,Arial,Helvetica,sans-serif;}
            .YearMonthOver{font-weight:normal; color:#000000; cursor:hand; font-family: Verdana,Arial,Helvetica,sans-serif;}
          
            .Month{font-weight:normal; height:30px; text-align:center; color:#006666; cursor:hand; font-family: Verdana,Arial,Helvetica,sans-serif;}
            .MonthOver{font-weight:normal; height:30px; text-align:center; color:#000000; cursor:hand; font-family: Verdana,Arial,Helvetica,sans-serif;}
          
            .Year{font-weight:normal; height:20px; text-align:center; color:#006666; cursor:hand; font-family: Verdana,Arial,Helvetica,sans-serif;}
            .YearOver{font-weight:normal; height:20px; text-align:center; color:#000000; cursor:hand; font-family: Verdana,Arial,Helvetica,sans-serif;}
          
            .PrevNext{cursor:hand; color:#006666;}
            .PrevNextOver{cursor:hand; color:#000000; font-weight:bold;}
          
            .Bottom{cursor:hand; color:#006666; font-size:10pt; text-align:center; font-family:Verdana,Arial,Helvetica,sans-serif;}
            .BottomOver{cursor:hand; color:#000000; font-size:10pt; text-align:center; font-family:Verdana,Arial,Helvetica,sans-serif;}
        </style>
    </head>
    <body>
        <input type="text" style="font-family: Verdana, Arial, Helvetica, sans-serif;" onclick="OpenCalendar(this)">
    </body>
</html>
<script language="vbscript" type="text/vbscript">
<!--
    document.write "<div id='divCalendar' style='background-color:#ccffff; text-align:center; position:absolute; z-index:1; width:160px; border:solid 1px gray; font-size:10pt; display:none;'></div>"
    dim AryCalendarDay(41)
    dim strCalendarDate, strCalendarYear, strCalendarMonth, strCalendarDay
    dim objCalendarText, divCalendarLeft, divCalendarTop
    dim AryWeekDays
    dim strCalendarType
    AryWeekDays = Array("", "", "", "", "", "", "")
    strCalendarType = "D"
  
    function CreateCalendar()
        dim strHtml
        strHtml = ""
        strHtml = strHtml & "<table cellpadding='0' cellspacing='0' border='0' style='width:100%; border-bottom:solid 1px #cccccc; color:#006666;'><tr>"
        strHtml = strHtml & "<td class='PrevNext' language='javascript' onmouseover='this.className=""PrevNextOver""' onmouseout='this.className=""PrevNext""' style='width:15%; text-align:left;' onclick='PrevMonth()'><<</td>"
        strHtml = strHtml & "<td class='YearMonth' language='javascript' onmouseover='this.className=""YearMonthOver""' onmouseout='this.className=""YearMonth""' onclick='YearClick()'>" & strCalendarYear & "</td>"
        strHtml = strHtml & "<td style='width:15%;'>年</td>"
        strHtml = strHtml & "<td class='YearMonth' language='javascript' onmouseover='this.className=""YearMonthOver""' onmouseout='this.className=""YearMonth""' onclick='MonthClick()'>" & strCalendarMonth & "</td>"
        strHtml = strHtml & "<td style='width:15%;'>月</td>"
        strHtml = strHtml & "<td class='PrevNext' language='javascript' onmouseover='this.className=""PrevNextOver""' onmouseout='this.className=""PrevNext""' style='width:15%; text-align:right;' onclick='NextMonth()'>>></td>"
        strHtml = strHtml & "</tr></table>"
      
        strHtml = strHtml & "<div id='divCalendarContent' style='text-align:center;'></div>"
      
        strHtml = strHtml & "<table border='0' cellpadding='0' cellspacing='0'>"
        strHtml = strHtml & "<col width='60%'><col width='10%'><col width='30%'>"
        strHtml = strHtml & "<tr><td colspan='2' style='height:2px;'/></tr><tr>"
        strHtml = strHtml & "<td class='Bottom' language='javascript' onmouseover='this.className=""BottomOver""' onmouseout='this.className=""Bottom""' onclick='GetDate1()'>" & strCalendarDate & "</td>"
        strHtml = strHtml & "<td></td>"
        strHtml = strHtml & "<td class='Bottom' language='javascript' onmouseover='this.className=""BottomOver""' onmouseout='this.className=""Bottom""' onclick='Clean()'>Clean</td>"
        strHtml = strHtml & "</tr><tr><td colspan='2' style='height:2px;'/></tr></table>"
      
        document.all.divCalendar.innerHTML = strHtml
        select case strCalendarType
            case "Y"
                document.all.divCalendarContent.innerHTML = SetYear
            case "M"
                document.all.divCalendarContent.innerHTML = SetMonth
            case else
                document.all.divCalendarContent.innerHTML = SetDay
        end select
      
        divCalendar.style.left = divCalendarLeft
        divCalendar.style.top = divCalendarTop + 20
        divCalendar.style.display = ""
    end function
  
    function SetYear()
        dim strHtml, intI
        strHtml = "<table cellpadding='0' cellspacing='0' style='width:90%; font-size:10pt;'>"
        strHtml = strHtml & "<tr><td style='height:10px;'></td></tr>"
        for intI=0 to 19
            if intI mod 4 = 0 then
                strHtml = strHtml & "<tr>"
            end if
            if (cint(strCalendarYear)+intI-10) = strCalendarYear then
                strHtml = strHtml & "<td class='Year' language='javascript' onmouseover='this.className=""YearOver""' onmouseout='this.className=""Year""' onclick='SelectYear()' style='color:red;'>" & cint(strCalendarYear)+intI-10 & "</td>"
            else
                strHtml = strHtml & "<td class='Year' language='javascript' onmouseover='this.className=""YearOver""' onmouseout='this.className=""Year""' onclick='SelectYear()'>" & cint(strCalendarYear)+intI-10 & "</td>"
            end if
            if intI mod 4 = 3 then
                strHtml = strHtml & "</tr>"
            end if
        next
        strHtml = strHtml & "</table>"
        SetYear = strHtml
    end function
  
    function SetMonth()
        dim strHtml, intI
        strHtml = "<table cellpadding='0' cellspacing='0'style='width:90%; font-size:10pt;'>"
        strHtml = strHtml & "<tr><td style='height:10px;'></td></tr>"
        for intI=0 to 11
            if intI mod 4 = 0 then
                strHtml = strHtml & "<tr>"
            end if
            if right("0"&(cint(intI)+1),2) = strCalendarMonth then
                strHtml = strHtml & "<td class='Month' language='javascript' onmouseover='this.className=""MonthOver""' onmouseout='this.className=""Month""' onclick='SelectMonth()' style='color:red;'>" & right("0"&(cint(intI)+1),2) & "</td>"
            else
                strHtml = strHtml & "<td class='Month' language='javascript' onmouseover='this.className=""MonthOver""' onmouseout='this.className=""Month""' onclick='SelectMonth()'>" & right("0"&(cint(intI)+1),2) & "</td>"
            end if
            if intI mod 4 = 3 then
                strHtml = strHtml & "</tr>"
            end if
        next
        strHtml = strHtml & "</table>"
        SetMonth = strHtml
    end function
  
    function SetDay()
        dim intEndDay, intI, intEnd
        dim strHtml
        intEndDay = dateadd("m", 1, cdate(strCalendarYear & "/" & strCalendarMonth & "/01"))
        intEndDay = dateadd("d", -1, cdate(intEndDay))
        intEndDay = Day(cdate(intEndDay))
        dim intDateFirst
        intDateFirst = weekday(cdate(strCalendarYear & "/" & strCalendarMonth & "/01"),vbSunday)
        if (cint(intDateFirst)+cint(intEndDay)) > 36 then
            intEnd = 41
        else
            intEnd = 34
        end if
        for intI=0 to intEnd
            if intI < intDateFirst - 1 then
                AryCalendarDay(intI) = 0
            elseif intI >= intEndDay + intDateFirst - 1 then
                AryCalendarDay(intI) = 0
            else
                AryCalendarDay(intI) = intI - intDateFirst + 2
            end if
        next
        strHtml = strHtml & "<table border='0' style='width:160px; font-size:10pt;' cellpadding='0' cellspacing='0'>"
        strHtml = strHtml & "<col width='15%'><col width='14%'><col width='14%'><col width='14%'><col width='14%'><col width='14%'><col width='15%'>"
        strHtml = strHtml & "<tr>"
        for intI=0 to 6
            strHtml = strHtml & "<td class='Date'>" & AryWeekDays(intI) & "</td>"
        next
        strHtml = strHtml & "</tr>"
        for intI=0 to intEnd
            if intI mod 7 = 0 then
                strHtml = strHtml & "<tr>"
            end if
            if AryCalendarDay(intI) <> "0" then
                if right("0"&AryCalendarDay(intI),2) = strCalendarDay then
                    strHtml = strHtml & "<td class='Today' onclick='GetDate()'>" & AryCalendarDay(intI) & "</td>"
                elseif intI mod 7 = 0 or intI mod 7 = 6 then
                    strHtml = strHtml & "<td class='Weekend' onclick='GetDate()'>" & AryCalendarDay(intI) & "</td>"
                else
                    strHtml = strHtml & "<td class='Day' onclick='GetDate()'>" & AryCalendarDay(intI) & "</td>"
                end if
            else
                strHtml = strHtml & "<td class='OtherMonth'>&nbsp;</td>"
            end if
            if intI mod 7 = 6 then
                strHtml = strHtml & "</tr>"
            end if
        next
        strHtml = strHtml & "</table>"
        SetDay = strHtml
        end Function
        function GetDate()
        strCalendarDay = window.event.srcElement.innerText
        strCalendarDate = strCalendarYear & "/" & right("0"&strCalendarMonth, 2) & "/" & right("0"&strCalendarDay, 2)
        objCalendarText.value = strCalendarDate
        divCalendar.style.display = "none"
    end function
  
    function GetDate1()
        strCalendarDate = strCalendarYear & "/" & right("0"&strCalendarMonth, 2) & "/" & right("0"&strCalendarDay, 2)
        objCalendarText.value = strCalendarDate
        divCalendar.style.display = "none"
    end function
  
    function OpenCalendar(objThis)
        set objCalendarText = objThis
        divCalendarLeft = objCalendarText.offsetLeft
        divCalendarTop = objCalendarText.offsetTop
        while not objCalendarText.offsetParent is nothing
            set objCalendarText = objCalendarText.offsetParent
            divCalendarLeft = divCalendarLeft + objCalendarText.offsetLeft
            divCalendarTop = divCalendarTop + objCalendarText.offsetTop
        wend
        set objCalendarText = objThis
        if isDate(objCalendarText.value) then
            strCalendarDate = Year(cdate(objCalendarText.value)) & "/" & right("0"&Month(cdate(objCalendarText.value)),2) & "/" & right("0"&Day(cdate(objCalendarText.value)),2)
        else
            strCalendarDate = Year(Now) & "/" & right("0"&Month(Now),2) & "/" & right("0"&Day(Now),2)
        end if
        strCalendarYear = Year(strCalendarDate)
        strCalendarMonth = right("0" & Month(strCalendarDate), 2)
        strCalendarDay = right("0" & Day(strCalendarDate), 2)
        call SetValue()
    end function
  
    function SetValue()
        while not isDate(strCalendarDate)
            strCalendarDay = cint(strCalendarDay) - 1
            strCalendarDate = strCalendarYear & "/" & right("0"&strCalendarMonth, 2) & "/" & right("0"&strCalendarDay, 2)
        wend
        strCalendarYear = Year(strCalendarDate)
        strCalendarMonth = right("0" & Month(strCalendarDate), 2)
        strCalendarDay = right("0" & Day(strCalendarDate), 2)
        call CreateCalendar()
    end function
  
    function YearClick()
        strCalendarType = "Y"
        call SetValue()
    end function
  
    function MonthClick()
        strCalendarType = "M"
        call SetValue()
    end function
  
    function SelectMonth()
        strCalendarMonth = window.event.srcElement.innerText
        strCalendarType = "D"
        strCalendarDate = strCalendarYear & "/" & right("0"&strCalendarMonth, 2) & "/" & right("0"&strCalendarDay, 2)
        call SetValue()
    end function
  
    function SelectYear()
        strCalendarYear = window.event.srcElement.innerText
        strCalendarType = "D"
        strCalendarDate = strCalendarYear & "/" & right("0"&strCalendarMonth, 2) & "/" & right("0"&strCalendarDay, 2)
        call SetValue()
    end function
  
    function PrevMonth()
        strCalendarDate = dateadd("m", -1, cdate(strCalendarDate))
        strCalendarType = "D"
        call SetValue()
    end function
  
    function NextMonth()
        strCalendarDate = dateadd("m", 1, cdate(strCalendarDate))
        strCalendarType = "D"
        call SetValue()
    end function
  
    function Clean()
        objCalendarText.value = ""
        divCalendar.style.display = "none"
    end function
-->
</script>

VB脚本虽然是ASP基石,不过非常不推荐,实际使用中,JS的客户端应用比VB广得多,很多方面确实也比VB强!

Q:1428196631,百度:开发地 即可找到我,有事请留言!
2010-06-18 16:00
快速回复:怎样用vbscript 写个日历
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.068273 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved