Function 错误';800a005e&x27;无效使用Null:';CDate';在ASP Classic VBScript中使用函数时
我创建了一个名为formatt的函数,并将其放在Function 错误';800a005e&x27;无效使用Null:';CDate';在ASP Classic VBScript中使用函数时,function,asp-classic,error-handling,vbscript,Function,Asp Classic,Error Handling,Vbscript,我创建了一个名为formatt的函数,并将其放在\include\basic\u function.asp 以下是该函数的代码: function FormatDT(ddate,format) ddate = cdate(ddate) Set re = New RegExp re.Pattern = "%." re.Global = True re.IgnoreCase = False 're.Mul
\include\basic\u function.asp
以下是该函数的代码:
function FormatDT(ddate,format)
ddate = cdate(ddate)
Set re = New RegExp
re.Pattern = "%."
re.Global = True
re.IgnoreCase = False
're.MultiLine = True
set matches = re.execute(format)
hasil = ""
tmp = format
for each match in matches
fmt = match.value
select case fmt
case "%d" hasil = day(ddate)
case "%D" hasil = right("00" & day(ddate),2)
case "%m" hasil = month(ddate)
case "%M" hasil = right("00" & month(ddate),2)
case "%b" hasil = left(MonthName(month(ddate)),3)
case "%B" hasil = MonthName(month(ddate))
case "%y" hasil = right(year(ddate),2)
case "%Y" hasil = year(ddate)
case "%h" hasil = hour(ddate)
case "%H" hasil = right("00" & hour(ddate),2)
case "%n" hasil = minute(ddate)
case "%N" hasil = right("00" & minute(ddate),2)
case "%s" hasil = second(ddate)
case "%S" hasil = right("00" & second(ddate),2)
case else hasil = replace(fmt,"%","")
end select
tmp = replace(tmp,fmt,hasil)
next
FormatDT = tmp
end function
我在这里使用这个函数:
<input style="text-align:center" class="label" style="width:6em;" type="text" id="txtDate" name="txtDate" size="12" value="<%=FormatDt(dtglvalid,"%M/%D/%Y")%>" >
当我加载页面时,我得到如下错误消息:
Microsoft VBScript运行时错误“800a005e”无效地使用Null:“cDate”/include/basic_function.asp,第234行 第234行位于
ddate=cdate(ddate)
如何解决此错误?ASP正在抱怨变量
ddate
为NULL
。查看您的代码,看起来变量dtglvalid
为NULL,它被传递给函数并导致错误。你可以这样做:
<input ... value="<% if not IsNull(dtglvalid) then Response.Write FormatDt(dtglvalid,"%M/%D/%Y") %>">