Avatar billede lund_dk Praktikant
12. september 2006 - 12:21 Der er 6 kommentarer og
1 løsning

Månedskalender

Jeg søger en kalender der ligner denne
www.lund.dk/kalender.asp

Koden for denne er her under - men syntes simpelthen den er så rodet,og giver mig problemer når jeg skal til at synkronisere med en database.

Nogen som kan hjælpe med at omkrive den lidt pænere, eller har anden tilsvarende?



<%
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 hnteknik Novice
12. september 2006 - 14:25 #1
Jeg går ud fra, at du har set denne her:

http://www.solit4u.dk/kalender/default.asp

Kører på Access/MS SQL/(MySQL)

Og jeg kan ikke bare give dig koden!
Avatar billede lund_dk Praktikant
12. september 2006 - 14:42 #2
Ja det er den stil..
men kan jeg ikke få fat i koden, ja så kan det jo være ligemeget..?!
Avatar billede hnteknik Novice
12. september 2006 - 14:51 #3
Den kan da købes for et mindre beløb!
hntekniksnabelapost4.tele.dk
Avatar billede lund_dk Praktikant
12. september 2006 - 15:37 #4
Naaah, ønsker jeg ikke..

Må være nogen der lige kan hjælpe mig med at lave måneds kalenderen.
1.
2.
3.
osv, skid være med ugenumre, lørdage, søndage osv.

Bare en generel månedskalender - så bygger jeg selv database løsning på bagefter.
Avatar billede cpufan Juniormester
12. september 2006 - 22:25 #5
Avatar billede lund_dk Praktikant
13. september 2006 - 20:22 #6
Er heller ikke det jeg søger :s
Avatar billede lund_dk Praktikant
14. september 2006 - 21:21 #7
lukker igen
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