charon
03-14-2003, 02:21 AM
hi,
I feel that my code is too long, but really can't think of better way to make it shorter (like creating function).
Intend to create a function for passing the mySQL statement, but seem like not much different.
Just curious to know, is there any other way to summarise the code.
Attached herewith the code.
david7777
03-14-2003, 07:07 AM
You could try something like below...
<%Dim i, fday, fmon, fyear, mySql, fday1, fmon1, fyear1
Sub sub_1(frmDate, toDat)
If Request.Form("project") = "All" Then
mySql = "SELECT * FROM futurelaunches WHERE Date BETWEEN #" & frmDate & "# AND #" & toDat &"# ORDER BY L_Date"
else
mySql = "SELECT * FROM futurelaunches WHERE Project = '" & TRIM(Request.Form("project")) & "' And Date BETWEEN #" & frmDate & "# AND #" & toDat &"# ORDER BY L_Date"
end if
End Sub
i = 1
fday1 = Request.Form("dday1")
fmon1 = Request.Form("dmon1")
fyear1 = Request.Form("dyear1")
fday = Request.Form("dday")
fmon = Request.Form("dmon")
fyear = Request.Form("dyear")
if fday <> "" and fmon <> "" and fday1 <> "" and fmon1 <> "" Then
sub_1(DateSerial(fyear1, fmon1, fday1), DateSerial( fyear, fmon, fday))
elseif fday = "" And fmon <> "" and fday1 <> "" and fmon1 <> "" Then
'give 0 as the day, then Date Serial will figure out you want the day before the first day of the given month, which is the last day of the prior month
sub_1(DateSerial(fyear1, fmon1, fday1), DateSerial(fyear, fmon + 1, 0) )
elseif fday <> "" and fmon <> "" and fday1 = "" and fmon1 <> "" Then
'day 1 of the Month in the year
sub_1(DateSerial(fyear1, fmon1, 1), DateSerial(fyear, fmon, fday))
elseif fday1 = "" and fday = "" and fmon <> "" and fmon1 <> "" Then
sub_1(DateSerial(fyear1, fmon1, 1), DateSerial(fyear, fmon+1, 0))
elseif fday1 = "" and fmon1 = "" and fday <> "" and fmon <> "" Then
sub_1(DateSerial(fyear1, 1, 1), DateSerial(fyear, fmon, fday))
elseif fday1 <> "" and fmon1 <> "" and fday = "" and fmon = "" Then
sub_1(DateSerial(fyear1, fmon1, fday1), DateSerial(fyear+1, 1, 0))
elseif fday1 = "" and fmon1 = "" and fday = "" and fmon <> "" Then
sub_1(DateSerial(fyear1, 1, 1), DateSerial(fyear+1, fmon+1, 0))
elseif fday1 = "" and fmon1 <> "" and fday = "" and fmon = "" Then
sub_1(DateSerial(fyear1, fmon1, 1), DateSerial(fyear+1, 1, 0))
else
sub_1(DateSerial(fyear1, 1, 1), DateSerial(fyear+1, 1, 0))
Response.Write fromDate & "<br>"
Response.Write toDate
End If
%>
Might not be the ultimate, but its a lot better...
Hope it helped
charon
03-14-2003, 12:57 PM
Thanks so much!
I seem like see you in other forums with name David 777
david7777
03-14-2003, 02:09 PM
It's very possible. I have posted quite a bit of JavaScript...
Hope the code helped! :thumbsup:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.