Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 15th, 2004, 10:10 AM
Authorized User
 
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default Date variables...

Hi All,
I am trying to utilize a date stored in the database and then compare it within a dropdown menu so that date will be specified. I have used the following command to split the date:

rsDate = oRSbt("DueDate")
DateArray = Split(rsDate,"/")

I am then using the part in the array to make up the date in three drop down boxes. I have successfully done the day and month but I am have terrible trouble with the year. I am using the following code:

<% BeginYear = Application("PAST_YEAR")
CurrentYear = Application("CURRENT_YEAR")
EndYear = Application("NEXT_YEAR") %>

<select name="rsYear" class="f" tabindex="7">
<option value="<%=BeginYear%>"<% if DateArray(2) = BeginYear then Response.Write(" selected") end if %>><%=BeginYear%></option>
<option value="<%=CurrentYear%>"<% if DateArray(2) = CurrentYear then Response.Write(" selected") end if %>><%=CurrentYear%></option>
<option value="<%=EndYear%>"<% if DateArray(2) = EndYear then Response.Write(" selected") end if %>><%=EndYear%></option>
</select>

However with this code the current year does not get selected in the drop down box...

Any ideas anyone

With many thanks for your time and assistance,

Paul J
 
Old January 15th, 2004, 02:36 PM
jb3 jb3 is offline
Registered User
 
Join Date: Oct 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The reason this is not working is that this code results in a common error with undeclared variable types. ASP is getting the value from the selector and it assigns it to a variant as type string, while your datearray value is probably a variant of type integer or some numeric type. When you 'test' them using If then - they will never be equal, hence you do not get what you expect...

Below is the sample page I created to verify this for you - save it as "test.asp" in your local web and then uncomment/comment the two lines for DateArray - to see how the page reacts.

Regards
John

<%
'DateArray = request.form("rsYear")
DateArray = cint(request.form("rsYear"))

'BeginYear = Application("PAST_YEAR")
'CurrentYear = Application("CURRENT_YEAR")
'EndYear = Application("NEXT_YEAR")

BeginYear = 2003
CurrentYear = 2004
EndYear = 2005

%>

<html>
<body>

<form name="frmForm" method="post" action="test.asp">

<select name="rsYear"tabindex="7" OnChange="submit()">
  <option value="<%=BeginYear%>"<% if DateArray = BeginYear then Response.Write(" selected") end if %>><%=BeginYear%></option>
  <option value="<%=CurrentYear%>"<% if DateArray = CurrentYear then Response.Write(" selected") end if %>><%=CurrentYear%></option>
  <option value="<%=EndYear%>"<% if DateArray = EndYear then Response.Write(" selected") end if %>><%=EndYear%></option>
</select>

</form>
</body>
</html>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Show Images from Start Date thru Date istcomnet Classic ASP Basics 2 May 23rd, 2008 07:12 AM
Passing date variables into a sql statement hood8jmark Excel VBA 1 May 1st, 2008 01:05 PM
how to declare date variables rehana Beginning PHP 1 December 15th, 2003 05:56 PM
DTS Import ( Date string to Date field) gfowajuh SQL Server 2000 1 September 30th, 2003 06:28 AM
Convert String Date to Date for a SQL Query tdaustin Classic ASP Basics 4 July 7th, 2003 06:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.