ASP两个比较终极写法
ASP内置函数在比较上一定要判断是否为空后,在用内置函数转换类型进行比较,不然都是通过的。keai = ""
if cstr(keai) = 1 then
response.write 1
end if '错误输出了
keai = ""
if int() = 1 then
response.write 2
end if'错误输出了
kong = ""
response.write len(kong)
if len(kong) = 1 then
response.write 3
end if'错误输出了
response.write "<br>"
'if LiGeBiJiao_config1(22,"22",0) then
'if LiGeBiJiao_config1(rs("ceshi_datetime"),"2012-5-1 10:10:10",0) then
'if LiGeBiJiao_config1(rs("ceshi_datetime"),"2012-5-1 10:10:10",1) then '判断是否为空 空为true
'if LiGeBiJiao_config1(rs("ceshi_datetime"),2012-5-1 10:10:10,0) then '错误写法
'if LiGeBiJiao_config1(cstr(),22,0) then '错误写法
'if LiGeBiJiao_config1(clng(),"22",0) then '错误写法
'if LiGeBiJiao_config1(int(),"22",0) then '错误写法
if LiGeBiJiao_config1(rs("ceshi_datetime"),"2",1) then
response.write 1
end if'正确写法
Function LiGeBiJiao_config1(byval diyige,byval dierge,byval kongpan) 'byval byref kongpan 只能 0 或者 1
'on error resume next
'response.write cstr(diyige)&"<br>"
'response.write dierge
'response.end
dim kong11,kong22,tmpkong,tmpType,tmpzhi
'if kongpan = "" or not isnumeric(kongpan) then
' response.write "LiGeBiJiao_config1 调用错误"
' response.end
' end if
'//////
kong11 = 0 : kong22 = 0 : LiGeBiJiao_config1 = false
'''''
tmpkong = diyige
Select Case VarType(tmpkong)
Case 0, 1
kong11 = 1
Case 8
If Len(tmpkong) = 0 Then
kong11 = 1
End If
Case 9
tmpType = TypeName(tmpkong)
If (tmpType = "Nothing") Or (tmpType = "Empty") Then
kong11 = 1
End If
Case 8192, 8204, 8209
If UBound(tmpkong) = -1 Then
kong11 = 1
End If
End Select
if int(kongpan) = 1 then
if int(kong11) = 1 then
LiGeBiJiao_config1 = true
end if
exit function
end if
'''''''//////
tmpkong = dierge
Select Case VarType(tmpkong)
Case 0, 1
kong22 = 1
Case 8
If Len(tmpkong) = 0 Then
kong22 = 1
End If
Case 9
tmpType = TypeName(tmpkong)
If (tmpType = "Nothing") Or (tmpType = "Empty") Then
kong22 = 1
End If
Case 8192, 8204, 8209
If UBound(tmpkong) = -1 Then
kong22 = 1
End If
End Select
' response.write kong22
' response.end
'''''''//////
if int(kong11)=1 and int(kong22)=1 then
LiGeBiJiao_config1 = true
exit Function
end if
if int(kong11)=0 and int(kong22)=0 then
'response.write dierge
'response.end
'if diyige = dierge then '错误写法
if cstr(diyige) = cstr(dierge) then
LiGeBiJiao_config1 = true
end if
end if
End Function
[ 本帖最后由 ysf0181 于 2013-7-18 15:35 编辑 ]