PDA

View Full Version : Function


Leeus
01-13-2003, 03:25 PM
I created the following function

Function sqldate(dateinput)
dim finaloutput,dayval,monval,yearval,textmon

dayval = day(dateinput)
monval = month(dateinput)
yearval = year(dateinput)
finaloutput = dayval & "-" & textmon & "-" & yearval
select case monval
case "1"
textmon= "JAN"
case "2"
textmon= "FEB"
case "3"
textmon= "MAR"
case "4"
textmon= "APR"
case "5"
textmon= "MAY"
case "6"
textmon= "JUN"
case "7"
textmon= "JUL"
case "8"
textmon= "AUG"
case "9"
textmon= "SEP"
case "10"
textmon= "OCT"
case "11"
textmon= "NOV"
case "12"
textmon= "DEC"
end select

finaloutput = dayval & "-" & textmon & "-" & yearval
'response.write(finaloutput)

end function


It works fine if I keep the response.write in but what I want to achieve is e.g. datevar= sqldate(date()) then response.write(datevar), this doesn't seem to work though, any ideas?

codefox
01-13-2003, 03:32 PM
Give sqldate=finaloutput at the end of the function, before "end function"

Leeus
01-13-2003, 03:55 PM
It works fine, thanks.

whammy
01-14-2003, 12:45 AM
Plus, I know there's a better way to do this, because I've done it (regarding SQL date format) but I don't have the code handy...

But why do a select case for all those numbers? Why don't you make the VALUE of the select option a NUMBER instead of text?!? You can display whatever you want, even the entire month name, example:


<%
Dim indent, i
indent = Space(5)
Response.Write("<form id=""monthform"" action=""months.asp"" method=""post"">" & vbCrLf)
Response.Write("<select name=""month"">" & vbCrLf)
For i = 1 to 12
If CStr(i) = Request.Form("month") Then
Response.Write(indent & "<option value=""" & i & """ selected=""selected"">" & MonthName(i) & "</option>" & vbCrLf)
Else
Response.Write(indent & "<option value=""" & i & """>" & i & "</option>" & vbCrLf)
End If
Next
Response.Write("</select>" & vbCrLf)
Response.Write("<input type=""submit"" value=""Submit"">" & vbCrLf)
Response.Write("</form>" & vbCrLf)
%>

Just an example, but that should give you the idea.

At the very least, I'd make the monthnames an array, like:

monthnames = "JAN|FEB|MAR|APR|...etc"
monthnames = Split(monthnames,"|") ' This turns monthnames into an array without having to Dim it as one!

and use monthname + 1, instead of using a select case... might be less efficient (not sure) but it's much less code... :)