gpt4 book ai didi

function - 错误 '800a005e' 无效使用 Null : 'CDate' when using a function in ASP Classic-VBScript

转载 作者:行者123 更新时间:2023-12-03 07:42:29 24 4
gpt4 key购买 nike

我制作了一个名为 FormatDT 的函数,并将其放在 \include\basic_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 runtime error '800a005e' Invalid use of Null: 'cDate'
/include/basic_function.asp, line 234



第 234 行位于 ddate = cdate(ddate)
如何解决这个错误?

最佳答案

ASP 提示变量 ddate正在 NULL .查看您的代码,它看起来像变量 dtglvalid是 NULL ,它被传递给函数并导致错误。您可以执行以下操作:

<input ... value="<% if not IsNull(dtglvalid) then Response.Write FormatDt(dtglvalid,"%M/%D/%Y") %>">

关于function - 错误 '800a005e' 无效使用 Null : 'CDate' when using a function in ASP Classic-VBScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10682127/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com