<code> Konkatenera strängar är väldigt fult. Tar onödigt mycket prestanda.Kalender ?
Public Function RenderCalendar(ByVal vlngYear, ByVal vlngMonth) 'As String
'Declarations
Dim strResult 'As String
Dim lngDaysInMonth 'As Long
Dim lngDay 'As Long
Dim lngWeekday 'As Long
'Init variables
lngDaysInMonth = GetDaysInMonth(vlngYear, vlngMonth)
'Render
strResult = strResult & "<table border=""0"" width=""80%"">"
strResult = strResult & "<tr>"
strResult = strResult & "<td>Må</td>"
strResult = strResult & "<td>Ti</td>"
strResult = strResult & "<td>On</td>"
strResult = strResult & "<td>To</td>"
strResult = strResult & "<td>Fe</td>"
strResult = strResult & "<td>Lö</td>"
strResult = strResult & "<td><font color=""#FF0000"">Sö</font></td>"
strResult = strResult & "</tr>"
strResult = strResult & "<tr>"
'Loop, render empty
For lngWeekday = 1 To Weekday(DateSerial(vlngYear, vlngMonth, 1), 2) - 1
strResult = strResult & "<td> </td>"
Next
'Loop
For lngDay = 1 To lngDaysInMonth
'Render
strResult = strResult & "<td bgColor=""#FFFFFF"" onMouseOver=""this.style.background='#E8E8E8'"" onMouseOut=""this.style.background='#FFFFFF'"">"
'Öppnar db
call openConn()
set oRS = server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM tbl_Calendar"
oRS.Open strSQL, dbc
If oRS.EOF Then
strResult = strResult & "" &lngDay &""
Else
strResult = strResult & "" &lngDay &""
End If
'Stänger db
Call closeConn()
strResult = strResult & "</td>"
'Set weekday
lngWeekday = lngWeekday + 1
'Check weekday
If lngWeekday > 7 And lngDay < lngDaysInMonth Then
'Render
strResult = strResult & "</tr><tr>"
'Set weekday
lngWeekday = 1
End If
Next
'Check weekday
If lngWeekday > 7 Then
'Loop, render empty
For lngWeekday = Weekday(DateSerial(vlngYear, vlngMonth, lngDay), 2) To 7
'strResult = strResult & "<td> </td>"
Next
End If
'Render
strResult = strResult & "</tr>"
strResult = strResult & "</table>"
'Return result
RenderCalendar = strResult
End Function
</code>
Hej ,
bygger min kalender på detta vis, men nu vill jag hämta allt från en Access DB och göra länkar av dom datum som finns i DB.
Men jag får inte till det , någon som har några tips ?Sv: Kalender ?
Det skulle hjälpa om du beskrive din datastruktur och ger exempeldata.
Men jag tror detta är ett steg i rätt riktning.
Public Sub RenderCalendar(ByVal vlngYear, ByVal vlngMonth) 'As String
'Declarations
Dim strResult 'As String
Dim lngDaysInMonth 'As Long
Dim lngDay 'As Long
Dim lngWeekday 'As Long
'Init variables
lngDaysInMonth = GetDaysInMonth(vlngYear, vlngMonth)
'Render
Response.Write "<table border=""0"" width=""80%"">"
Response.Write "<tr>"
Response.Write "<td>Må</td>"
Response.Write "<td>Ti</td>"
Response.Write "<td>On</td>"
Response.Write "<td>To</td>"
Response.Write "<td>Fe</td>"
Response.Write "<td>Lö</td>"
Response.Write "<td><font color=""#FF0000"">Sö</font></td>"
Response.Write "</tr>"
Response.Write "<tr>"
'Loop, render empty
For lngWeekday = 1 To Weekday(DateSerial(vlngYear, vlngMonth, 1), 2) - 1
Response.Write "<td> </td>"
Next
call openConn()
'Öppnar db
set oRS = server.CreateObject("ADODB.Recordset")
'Loop
For lngDay = 1 To lngDaysInMonth
'Render
Response.Write "<td bgColor=""#FFFFFF"" onMouseOver=""this.style.background='#E8E8E8'"" onMouseOut=""this.style.background='#FFFFFF'"">"
strSQL = "SELECT * FROM tbl_Calendar WHERE Date=#" & vlngYear & "-" & Right("0" & vlngMonth, 2) & "-" & Right("0" & lngDay, 2) & "#"
oRS.Open strSQL, dbc
If oRS.EOF Then
Response.Write "" &lngDay &""
Else
Response.Write "" &lngDay &""
End If
oRS.Close
Response.Write "</td>"
'Set weekday
lngWeekday = lngWeekday + 1
'Check weekday
If lngWeekday > 7 And lngDay < lngDaysInMonth Then
'Render
Response.Write "</tr><tr>"
'Set weekday
lngWeekday = 1
End If
Next
'Stänger db
Call closeConn()
'Check weekday
If lngWeekday > 7 Then
'Loop, render empty
For lngWeekday = Weekday(DateSerial(vlngYear, vlngMonth, lngDay), 2) To 7
Response.Write "<td> </td>"
Next
End If
'Render
Response.Write "</tr>"
Response.Write "</table>"
End Sub