ASP中的EVAL函数使用教程

2015-08-12 15:59:53来源:作者:人点击

近两日，学习了ASP的EVAL函数。感觉上很实用，如果使用得当，能减轻很多代码的编写量，也使得代码更加简洁明了。

EVAL函数的原型：

EVAL（expression）

b=EVAL（"A=5"）

b=EVAL（"A"）

b=EVAL（"CustFunction(2,3)"）

Dim zID, zOrder, zOrderBy, zCurPage
Dim zPageCount, zURL

Dim zMM(), zMMPara()

redim zMM(0)
redim zMMPara(0)

ReDim Preserve zMM(UBound(zMM) + 1)
ReDim Preserve zMMPara(UBound(zMM))
If ParaType = 1 Then
zMM(UBound(zMM)) = Para & "=" & Default
Else
zMM(UBound(zMM)) = Para & "=""" & Default & """"
End If
zMMPara(UBound(zMM)) = Para
End Sub

Public Function GetURL(URL)
Dim i, tS
tS = ""
For i = 1 To UBound(zMM)
If Eval(zMM(i)) = False Then
tS = tS & "&" & Mid(zMMPara(i), 2) & "=" & Eval(zMMPara(i))
End If
Next

If Len(tS) > 0 Then
GetURL = URL & "?" & Mid(tS, 2)
Else
GetURL = URL
End If
End Function

Public Function GetNav(Index)
Dim tS
If zPageCount = 1 Then
GetNav = ""
End If
Select Case Index
Case 1
If zCurPage = 1 Then
GetNav = ""
Else
tS = zCurPage
zCurPage = 1
GetNav = "<span><a href=" & GetURL(zURL) & ">首页</a></span>"
zCurPage = tS
End If
Case 2

If zCurPage = 1 Then
GetNav = ""
Else
tS = zCurPage
zCurPage = zCurPage - 1
GetNav = "<span><a href=" & GetURL(zURL) & ">上一页</a></span>"
zCurPage = tS
End If

Case 3
If zCurPage = zPageCount Then
GetNav = ""
Else
tS = zCurPage
zCurPage = zCurPage + 1
GetNav = "<span><a href=" & GetURL(zURL) & ">下一页</a></span>"
zCurPage = tS
End If

Case 4
If zCurPage = zPageCount Then
GetNav = ""
Else
tS = zCurPage
zCurPage = zPageCount
GetNav = "<span><a href=" & GetURL(zURL) & ">末页</a></span>"
zCurPage = tS
End If

End Select
End Function