The Eval function in the vbscript| function JavaScript allows us to easily manipulate a range of variables (a1,a2,a3,...... )。 Since VBScript 5.0, we can also use this feature in ASP!
I am grateful to the programming enthusiasts Forum friends raised the problem, let me learn more about this very useful function.
Like JavaScript, eval () evaluates the value of the variable in which the string is represented and returns, such as Eval ("a" & "1"), which returns the value of A1. However, this eval () has a different function than JavaScript. I tried it and found that there were mainly the following: The Eval function in VBScript can only read the return value, not the variable it represents, that is, we cannot assign a value to A1 with Eval ("a" & "1").
The friend raised the question by assigning a long string ("2005081200507120050612005051") to a set of 7 characters to a sequence of variables A1,a2,a3,...。
If it is assigned to an array, then we can create a dynamic array:
<%
Use= "2005081200507120050612005051"
Dim myarray ()
ReDim myarray (0)
For I=1 to Len step 7
ReDim myarray (UBound (myarray) +1) ' Add the array capacity to 1
MyArray (UBound (myarray)) =mid (use,i,7)
Next
%>
Now to assign a value to a series variable, we have to introduce another function, execute (). The function is to treat the string as a VBScript statement execution, such as execute ("a" & "1=" &100 "), which executes the following statement: A1=100.
Accordingly, we can write the following code according to the request of the friend:
<%
Use= "2005081200507120050612005051"
Dim n ' index 1,2,3 as variable a,...
N=1
For I=1 to Len step 7
Execute "Dim a" &cstr (n) & ": A" &cstr (n) & "=" &mid (use,i,7)
' Execute statement Dim a:a1=mid (use,i,7)
N=n+1
Next
%>
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.