Using the Eval function in ASP tutorial

Source: Internet
Author: User
Tags eval

In the last two days, I learned the Eval function for ASP. Feel very practical, if used properly, can reduce the number of code writing, but also make the code more concise and clear.


Prototype of the Eval function:

EVAL (expression)

Where expression is a string parameter, can be an expression, can be a variable, or even a statement. But they all come in the form of strings.

For example

B=eval ("a=5")

This code means to determine whether the value of variable A is equal to 5, and returns True, not equal to false return. Equivalent to b= (a=5). However, the flexibility of the function is that his arguments are in the form of strings. So that I can construct a string that is equivalent to executing the statement of that string.

Again for example:

B=eval ("A")

The code is the value of the return variable A. Because the ASP is implicitly defined, an empty string is returned when a is not defined.

In the example:

B=eval ("custfunction (2,3)")

This code executes the function custfunction (2,3) and returns the value to B. See this, think of what? Well, polymorphic.

Since the Eval function's parameters are strings, my logical construction of strings can achieve many seemingly impossible things.

The following section of code uses the Eval function to implement the code that constructs the link URL. has a certain versatility.
Dim ZID, ZOrder, Zorderby, Zcurpage
Dim Zpagecount, Zurl

Dim zmm (), Zmmpara ()

ReDim zmm (0)
ReDim Zmmpara (0)

Public Sub Addpara (Para, Default, Paratype)
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) & "> Home </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) & "> Prev </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) & "> next page </a></span>"
Zcurpage = TS
End If

Case 4
If zcurpage = Zpagecount Then
Getnav = ""
Else
TS = Zcurpage
Zcurpage = Zpagecount
Getnav = "<span><a href=" & GetURL (Zurl) & "> last page </a></span>"
Zcurpage = TS
End If

End Select
End Function

This code, make full use of the Eval function for the page's four parameters Zid, ZOrder, Zorderby, zcurpage URL construction. and has certain universality. Just make the right changes.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.