Avatar billede lund_dk Praktikant
19. april 2005 - 12:53 Der er 2 kommentarer og
1 løsning

Simpel kalender

Er der nogen som kan hjælpe mig med hvordan jeg stiller en meget simpel kalender op.

den skal følgende:
1. vise et helt måned af gangen (se eks)
2. Drop-down vælger hvor man skal kunne vælge at se visning for bestemt måned og år


eks. 1
fre 1.
lør 2.
søn 3.
man 4.
osv.

Nogen som kan hjælpe mig? :)
Avatar billede moejensen Nybegynder
19. april 2005 - 13:02 #1
det er ikke en simpel kalender at lave, da det kræver lidt. Men her er et eksempel lavet af vbCoder:

<%
option explicit

session.lcid = 1033

'extracted data
dim current_date, first_day, this_day, this_week, this_month, this_year, last_day, day_of_week

' counters
dim counter, wdays, weeks, start_week, week_calc, num_weeks_in_year, right_year_divided

' Create an array to display the month names
dim month_name(12)
month_name(1)="JANUAR "
month_name(2)="FEBRUAR "
month_name(3)="MARTS "
month_name(4)="APRIL "
month_name(5)="MAJ "
month_name(6)="JUNI "
month_name(7)="JULI "
month_name(8)="AUGUST "
month_name(9)="SEPTEMBER "
month_name(10)="OKTOBER "
month_name(11)="NOVEMBER "
month_name(12)="DECEMBER "

dim day_name(7)
day_name(1)="M "
day_name(2)="T "
day_name(3)="O "
day_name(4)="T "
day_name(5)="F "
day_name(6)="L "
day_name(7)="S "

' create a variable for the current date
current_date=date()

' create a variable for the current year from the current date
this_year=year(current_date)

' create a variable for the current month from the current date
this_month=month(current_date)

' create a variable for the current day from the current date
this_day=day(current_date)

' create a variable for the current week from the current date
this_week = DatePart("WW", current_date)

' create a variable for the week number which the first day of the month is part of
start_week = weekNumber (dateSerial(this_year, this_month , 1))

' create a variable for the current day number from the current date assuming monday is the first day
day_of_week = DatePart("W", current_date, vbMonday)

' create a variable for the first day from the current date
first_day = weekday(dateSerial(this_year, this_month, 00))

' create a variable for the length of the current month
select case this_month

  ' For the months with 31 wdays set the end date
  case "1","3","5","7","8","10","12"
    'january
    'march
    'may
    'july
    'august
    'october
    'december
    last_day = 31
   
    ' For February set the end date by applying the leap year rules
    ' if the year is evenly divisable by 4 or ending in 00 divisable by 400
 
  case "2"
    'february
    last_day = 28
   
    right_year_divided=this_year/4
   
    if right_year_divided = cint(right_year_divided) then
      last_day = 29
    end if
   
    if right(this_year,2)="00" then
      right_year_divided=this_year/400
   
      if right_year_divided = cint(right_year_divided) then
        last_day = 29
      end if ' end check of year values
    end if ' end check for new century
 
  ' All the rest of the months have 30 wdays
  case "4","6","9","11"
    'april
    'june
    'september
    'november
    last_day = 30

end select ' end selct of month

%>
<html>
<title>Kalender</title>
<head>
<meta http-equiv="Content-Language" content="da">
</head>

<body>

<p align="center">&nbsp;</p>
<table border="0" width="70%" id="table1" cellspacing="0" align="center">
    <%
    'page header start
    %>
    <tr>
        <td width="57" style="border-top: solid 2px #000000;border-bottom: solid 2px #000000;">&nbsp;</td>
        <td align="center" style="border-top: solid 2px #000000;border-bottom: solid 2px #000000;"><b><%=month_name(this_month)%> <%=this_year%> - <%=this_month%>. MÅNED</b></td>
        <td width="42" style="border-top: solid 2px #000000;border-bottom: solid 2px #000000;">&nbsp;</td>
    </tr>
    <%
    'page header end

    '**************************************************
    ' Loop for the first week
    '**************************************************
    for counter = 1 to 7
        ' Check to see what day the first of the month falls on
        if counter > first_day - 1 then
         
          ' Count for wdays
          wdays = wdays + 1
          %>
          <tr>
            <%             
            if counter = first_day or counter = 1 then
           
              if DatePart("W", this_year & "-" & this_month & "-" & formatNumber(wdays,0,true,false,false), vbMonday) = 6 then
                ' grey the first cell
                %>
                  <td bgcolor="#CCCCCC" width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%><%=wdays%></td>
                  <td style="border-bottom: solid 1px #000000;">&nbsp;</td>
                  <td width="42" style="border-bottom: solid 1px #000000;"><%=start_week%></td>
                <%           
              elseif DatePart("W", this_year & "-" & this_month & "-" & formatNumber(wdays,0,true,false,false), vbMonday) = 7 then
                ' sunday - grey out cell
                %>
                <td bgcolor="#CCCCCC" width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%><%=wdays%></td>
                <td bgcolor="#CCCCCC" style="border-bottom: solid 1px #000000;">&nbsp;</td>
                <td bgcolor="#CCCCCC" width="42" style="border-bottom: solid 1px #000000;"><%=start_week%></td>
                <%
              else
              %>
                <td width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%><%=wdays%></td>
                <td style="border-bottom: solid 1px #000000;">&nbsp;</td>
                <td width="42" style="border-bottom: solid 1px #000000;"><%=start_week%></td>
              <%           
              end if
     
            elseif DatePart("W", this_year & "-" & this_month & "-" & formatNumber(wdays,0,true,false,false), vbMonday) = 6 then
              ' grey the first cell
              %>
                <td bgcolor="#CCCCCC" width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%> <%=wdays%></td>
                <td style="border-bottom: solid 1px #000000;">&nbsp;</td>
                <td width="42" style="border-bottom: solid 1px #000000;">&nbsp;</td>
              <%           
           
            elseif DatePart("W", this_year & "-" & this_month & "-" & formatNumber(wdays,0,true,false,false), vbMonday) = 7 then
              ' sunday - grey out cell
              %>
              <td bgcolor="#CCCCCC" width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%> <%=wdays%></td>
              <td bgcolor="#CCCCCC" style="border-bottom: solid 1px #000000;">&nbsp;</td>
              <td bgcolor="#CCCCCC" width="42" style="border-bottom: solid 1px #000000;">&nbsp;</td>
              <%
           
            else
            ' no grey on normal and saturday
            %>
              <td width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%> <%=wdays%></td>
              <td style="border-bottom: solid 1px #000000;">&nbsp;</td>
              <td width="42" style="border-bottom: solid 1px #000000;">&nbsp;</td>
            <%
            end if
            %>
          </tr>           
          <%     
        end if ' End check for first day of the week
    next
       
    '**************************************************
    ' Loop for the remaining weeks in the month
    '**************************************************
    for weeks = 1 to 5
     
      start_week = weeknumber(dateserial(this_year,this_month, wdays+1))

     
      '**************************************************
      ' Loop the week
      '**************************************************
      for counter = 1 to 7
                 
        ' increment wdays
        wdays = wdays + 1
       
        if wdays <= last_day then
               
          %>
          <tr>
          <%             
            if counter = 1 then
           
              if DatePart("W", this_year & "-" & this_month & "-" & formatNumber(wdays,0,true,false,false), vbMonday) = 6 then
                ' grey the first cell
                %>
                  <td bgcolor="#CCCCCC" width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%><%=wdays%></td>
                  <td style="border-bottom: solid 1px #000000;">&nbsp;</td>
                  <td width="42" style="border-bottom: solid 1px #000000;"><%=start_week%></td>
                <%           
              elseif DatePart("W", this_year & "-" & this_month & "-" & formatNumber(wdays,0,true,false,false), vbMonday) = 7 then
                ' sunday - grey out cell
                %>
                <td bgcolor="#CCCCCC" width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%><%=wdays%></td>
                <td bgcolor="#CCCCCC" style="border-bottom: solid 1px #000000;">&nbsp;</td>
                <td bgcolor="#CCCCCC" width="42" style="border-bottom: solid 1px #000000;"><%=start_week%></td>
                <%
              else
              %>
                <td width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%><%=wdays%></td>
                <td style="border-bottom: solid 1px #000000;">&nbsp;</td>
                <td width="42" style="border-bottom: solid 1px #000000;"><%=start_week%></td>
              <%           
              end if
     
            elseif DatePart("W", this_year & "-" & this_month & "-" & formatNumber(wdays,0,true,false,false), vbMonday) = 6 then
              ' grey the first cell
              %>
                <td bgcolor="#CCCCCC" width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%> <%=wdays%></td>
                <td style="border-bottom: solid 1px #000000;">&nbsp;</td>
                <td width="42" style="border-bottom: solid 1px #000000;">&nbsp;</td>
              <%           
           
            elseif DatePart("W", this_year & "-" & this_month & "-" & formatNumber(wdays,0,true,false,false), vbMonday) = 7 then
              ' sunday - grey out cell
              %>
              <td bgcolor="#CCCCCC" width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%> <%=wdays%></td>
              <td bgcolor="#CCCCCC" style="border-bottom: solid 1px #000000;">&nbsp;</td>
              <td bgcolor="#CCCCCC" width="42" style="border-bottom: solid 1px #000000;">&nbsp;</td>
              <%
           
            else
            ' no grey on normal and saturday
            %>
              <td width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%> <%=wdays%></td>
              <td style="border-bottom: solid 1px #000000;">&nbsp;</td>
              <td width="42" style="border-bottom: solid 1px #000000;">&nbsp;</td>
            <%
            end if
            %>
          </tr>           
          <%     
        end if ' End check for first day of the week
      next
    next
    %>

</table>

</body>
</html>
<%Public Function WeekNumber(InDate)
Dim v1
Dim v2
Dim v3
Dim v4
Dim v5
Dim v6
Dim v7
v1=Days(InDate)
v4=Weekday(DateSerial(Year(InDate),1,1),vbUseSystemDayOfWeek)-1
v5=Weekday(DateSerial(Year(InDate),12,31),vbUseSystemDayOfWeek)-1
v2=7-(v4-1)   
v3=7-(v5-1)   
If v4=4 Or v5=4 Then v7=True Else v7=False
v6=(v1-v2-4)/7   
If v2=>4 Then WeekNumber=cint(v6)+2 Else WeekNumber=cint(v6)+1
If WeekNumber>52 And Not v7 Then WeekNumber=1   
If WeekNumber=0 Then WeekNumber=WeekNumber(DateSerial(Year(InDate)-1,12,31))
End Function
Public Function Days(v1)
Days=v1-DateSerial(Year(v1),1,0)
End Function%>
Avatar billede busschou Praktikant
19. april 2005 - 15:20 #2
Sværhedsgraden afhænger jo af hvad man vil..og detaljer kan altid komme på
Her er noget jeg har brugt til et reservations system.
Man kan jo snildt hive arragementer eller andet ud af en database svarende til datoen
Men det her gør vist som ønsket - opretter valg muligheder for måned og år og viser derefter dagene i en tabel
-------
<body>
Vælg den måned du ønsker reservere i <br/><br/>
<form name ="valg" method="post" action="index.asp">
    <table border="0">
        <tr>
            <td align="center">Måned</td>
            <td align="center">År</td>
            <td></td>
        </tr>
        <tr>
            <td>
                <select size="1" name="maaned">
                    <% for t = 1 to 12  %>
                    <option value="<%=t%>"><%=t%></option>
                    <% next %>
                </select>
            </td>
            <td>
                <select size="1" name="aar">
                <% for t = Year(Now) to Year(Now)+2  %>
                <option value="<%=t%>"><%=t%></option>
                <% next %>
                </select>
            </td>
            <td>
                <input type="submit" name="send" value="Vælg">
            </td>
    </table>
</form>
<%
if request.form("send") <> "" then
    maaned = request.form("maaned")
    aar = request.form("aar")
    dato1 = DateSerial(aar, maaned, 1)
    dato2 = DateAdd("m", 1, dato1)
    DaysInMonth = DateDiff("d", dato1, dato2)
    maaneder = Array("Januar","Februar","Marts","April","Maj","Juni","Juli","August","September","Oktober","November","December")
    dage = Array("S","M","T","O","T","F","L")
%>
<table border="1" width="100%">
    <tr>
        <td align="center" colspan="7"><b><%=maaneder(maaned-1)&" "&aar%></b></td>
    </tr>
    <tr>
        <td align="center"><b>Dag</b></td>
    </tr>
    <%
        for t=1 to DaysInMonth
        dato = DateSerial(aar,maaned,t)
        dag = dage(Weekday(dato)-1)  %>
<tr>
    <td align="left"><%=dag&" "&t%></td>
</tr>
<% next %>
</table>
<% end if %>
</body>
Avatar billede busschou Praktikant
19. april 2005 - 15:23 #3
Så vidt jeg ved er folks problemer med en kalender at finde antal dage i en måned og tage højde for skudår osv
Det gør jeg i ovenstående ved at tage den første i måneden, samt den første i måneden efter og finde differencen. Sådan :o) nemt og simpelt synes jeg :o)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester