Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calendar Control

Status
Not open for further replies.

DDR

Technical User
Aug 22, 2001
54
US
Does any one can give me some code sample to insert a calendar control in an Asp page?
 
Hi,

First of all you need to register MSCAL.OCX in Windows on all clients accessing your site. The file comes with 3 other files(MSCAL.DEP; MSCAL.CNT; MSCAL.HLP). I think it should work stand alone as well. If you use the next ASP/VBSript code it should work.

Advantage: Control is nice and very MS aplications like.
Disadvantage: Works on IE only and you must register MSCAL.OCX.

How to register:
Save MSCAL.OCX in c:\windows\system32(if your windows folder is named windows)
Open a command prompt and type, followed by enter:
regsvr32.exe c:\windows\system32\mscal.ocx

What does the code do:

Variable 'browser' is filled with a textstring containing information on what browser you use.
If the string contains "MSIE" then you use internet explorer and the Active-X control is used, the current date is already picked (the user can't select invalid dates like for example: 2/31/2001)
If another browser is used it creates 3 dropdowns to select a date in a more conventional way(you have to check afterwards if a valid date is selected, also you have to format the 3 values into a date). Good luck.

Louie66 [2thumbsup]


<% browser = Request.ServerVariables(&quot;HTTP_USER_AGENT&quot;) %>
<% If Instr(browser, &quot;MSIE&quot;) <> 0 then %>
<OBJECT classid=&quot;clsid:8E27C92B-1264-101C-8A2F-040224009C02&quot; id=SelectedDate name=SelectedDate style=&quot;LEFT: 0px; TOP: 0px&quot;>
<PARAM NAME=&quot;_Version&quot; VALUE=&quot;524288&quot;>
<PARAM NAME=&quot;_ExtentX&quot; VALUE=&quot;7620&quot;>
<PARAM NAME=&quot;_ExtentY&quot; VALUE=&quot;5080&quot;>
<PARAM NAME=&quot;_StockProps&quot; VALUE=&quot;1&quot;>
<PARAM NAME=&quot;BackColor&quot; VALUE=&quot;-2147483633&quot;>
<PARAM NAME=&quot;Year&quot; VALUE=&quot;<%= year(NOW()) %>&quot;>
<PARAM NAME=&quot;Month&quot; VALUE=&quot;<%= month(NOW()) %>&quot;>
<PARAM NAME=&quot;Day&quot; VALUE=&quot;<%= day(NOW()) %>&quot;>
<PARAM NAME=&quot;DayLength&quot; VALUE=&quot;1&quot;>
<PARAM NAME=&quot;MonthLength&quot; VALUE=&quot;2&quot;>
<PARAM NAME=&quot;DayFontColor&quot; VALUE=&quot;0&quot;>
<PARAM NAME=&quot;FirstDay&quot; VALUE=&quot;1&quot;>
<PARAM NAME=&quot;GridCellEffect&quot; VALUE=&quot;1&quot;>
<PARAM NAME=&quot;GridFontColor&quot; VALUE=&quot;10485760&quot;>
<PARAM NAME=&quot;GridLinesColor&quot; VALUE=&quot;-2147483632&quot;>
<PARAM NAME=&quot;ShowDateSelectors&quot; VALUE=&quot;-1&quot;>
<PARAM NAME=&quot;ShowDays&quot; VALUE=&quot;-1&quot;>
<PARAM NAME=&quot;ShowHorizontalGrid&quot; VALUE=&quot;-1&quot;>
<PARAM NAME=&quot;ShowTitle&quot; VALUE=&quot;-1&quot;>
<PARAM NAME=&quot;ShowVerticalGrid&quot; VALUE=&quot;-1&quot;>
<PARAM NAME=&quot;TitleFontColor&quot; VALUE=&quot;10485760&quot;>
<PARAM NAME=&quot;ValueIsNull&quot; VALUE=&quot;0&quot;>
</OBJECT>
<% Else %>
<SELECT name=&quot;month_s&quot;>
<%
For m = 1 to 12
if month(NOW()) = m then
Response.Write(&quot;<Option selected value=&quot; & m & &quot;>&quot; & m )
else
Response.Write(&quot;<Option value=&quot; & m & &quot;>&quot; & m )
end if
Next
%>
</SELECT>
<SELECT name=&quot;date_s&quot;>
<%
For d = 1 to 31
if day(NOW()) = d then
Response.Write(&quot;<Option selected value=&quot; & d & &quot;>&quot; & d )
else
Response.Write(&quot;<Option value=&quot; & d & &quot;>&quot; & d )
end if
Next
%>
</SELECT>
<SELECT name=&quot;year_s&quot;>
<%
For j = 1995 to 2020
if year(NOW()) = j then
Response.Write(&quot;<Option selected value=&quot; & j & &quot;>&quot; & j )
else
Response.Write(&quot;<Option value=&quot; & j & &quot;>&quot; & j )
end if
Next
%>
</SELECT>
<% End If %> Best regards,

René de Leeuw.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top