In VB scripts, you don't have to define variables or define their types explicitly in other scripting languages. A variable exists the first time you use it. However, this feature makes your code widely available in typing. If you incorrectly define a variable name in your code, a new variable will be created. Your script may not work properly, and you may not be aware of the error.
Transfer from: China Software network www.csdn.com.cn
When you use variables, you have to develop a habit of defining them, and all you have to do is test the Dim VariableName:
%<%dim intuserid%>%
Intuserid can now be used. For another safety net, use option Explicit. If you open option Explicit, you will send the wrong signal at any time using the variable. This sounds boring, but when your script goes wrong, he can give you some clues, or you'll have to find out where the error is.
To use option Explicit, take the following as the first line of your script:
<% Option Explicit%>
If you want to see what happens when you forget to define a variable, you can run the following code:
<% Option Explicit%>
<:% strName = Request.Form ("Name")%>
Because the StrName variable (Dim strName) is not defined, you will see the following errors occur:
Microsoft VBScript Runtime error ' 800A01F4 '
Variable is undefined: ' StrName '
/e/oe-test.asp, Line 10
Using Len
You can use the Len (string) function to determine the length of a string of text:
<%
Intstring = "This was a simple sentence."
Intstringlength = Len (intstring)
Response.Write "There are" & Intstringlength & "characters (including spaces) in the sentence shown:"
Response.Write "" & Intstring & ""
%>
If you want to know how Len works manually, you may want to ask the user to enter their five-digit code or three-bit pin form. Using Len, you've entered enough numbers.
Use Trim
The trimming string is something you want to get at the beginning. Many times, a string has an extra space at the beginning or end, and if you don't balance it, you may be worried about wasting time on those variables.
<% strName = Request.Form ("Name")
Strcheckname = "Amy Cowen"
If strName = Strcheckname THEN
Response.Write "Success! The names matched.
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