Technology of use ASP script
Tuesday, March 03, 2009 by rain
In VB script,You need not define variable to perhaps resemble the specific in other scenario language type that defines them.A variable exists when you are used for the first time.But,In the existence manuscript that this character lets your code is extensive.If you are in code,define name of a variable wrongly,So a new variable will be founded.Your script cannot work normally possibly,And you cannot realize this error likely also.
Turn from:Dynamic net makes guideline Www.knowsky.comWhen you use variable,The habit that you want nurturance to define them,What what you need to do is test Dim VariableName:
%%26lt;%Dim IntUserID%%26gt;%
IntUserID can be used now.For another safety net, use Option Explicit. If you open Option Explicit, the signal that you are using any variable moment to give out a mistake.This sounds very drab,But when your script produces a mistake,He can give you a few clue,Otherwise you should find out a mistake hardly to go out where.
To use Option Explicit, regard the group of your script as content the content below:
%26lt;% Option Explicit %%26gt;
If you want to look to forget when you,what condition can produce when defining variable,Can move below this bit of code:
%26lt;% Option Explicit %%26gt;
%26lt;:%StrName = Request.Form("Name") %%26gt;
Because StrName is variable (Dim StrName) was not defined,You will see hair be delivered of these mistakes:
Microsoft VBScript Runtime Error '800a01f4'
Variable Is Undefined: 'strName'
/ E/oe-test.asp, line 10
Use Len
The string together length that you can use Len(string) function to decide text:
%26lt;%
IntString = "This Is A Simple Sentence. IntString = "This Is A Simple Sentence..
IntStringLength = Len(IntString)
Response.Write "There Are " %26 IntStringLength %26 " Characters (including Spaces) In The Sentence Shown Below:"
Response.Write "" %26 IntString %26 " "
%%26gt;
If you want to know Len is how the hand begins construction,You can think you ask the user inputs their five digit word code or the form of three PIN.Use Len,Whether did your desired effect input sufficient number.
Use Trim
Trimming is strung together is the thing that you mean to beginning to be obtained.A lot of moment,One is strung together there is an extra space when begin or ending,If you are lopsided it,You may arrive between afraid billow take time on these variable.
%26lt;% StrName = Request.Form(%26quot;Name%26quot; )
StrCheckName = "Amy Cowen "
If StrName = StrCheckName THEN
Response.Write "Success! The Names Matched. The Names Matched..
Else
Response.Write "Sorry. The Names Do Not Match. The Names Do Not Match..
End If
%%26gt;
If the value of StrName is " Amy Cowen" ,In how because that is me,inputting it formal Box,Check two variable next same,The result is not,Because "Amy Cowen" is not " Amy Cowen. Because "Amy Cowen" is not " Amy Cowen..
No less,If you go to Name input in URL:
%26lt;% Response.Write %26quot; %26amp; ObjRec(%26quot;Name%26quot;) %26amp; %26quot;%26quot;%26gt;Your Site%26quot; %%26gt;
If any parts of the record in Name have extra space,Your will rapid executive mistake problem.
You can be amended one whole string together latter to the left or right carries out a process:
%26lt;% StrComments = Request.Form(%26quot;Comments%26quot; )
StrComments = Trim(strComments)
%%26gt;
Assume the user has been inputted::
"I Am Having Problems Installing The Software I Downloaded. "I Am Having Problems Installing The Software I Downloaded..
The nap statement above will the space with extra break up,Leave the content below only:
"I Am Having Problems Installing The Software I Downloaded. "I Am Having Problems Installing The Software I Downloaded..
Now,Return case of our " Amy Cowen" , if I added the script below,We can succeed:
StrName = Trim(strName)
In right nap, use Rtrim(string) . To the left nap, use Ltrim(string) .
Changeover
Begin to use when you with the language with similar VB when,You can make a few simple mistakes,Rectify quite for instance model 512 and string 512.If you realise before one 512 after mixing 512 it is different,The scenario that you can consider why to give out cannot work normally.
Hypothesis,You are deferent the ID of a file arrives in ASP script,Use Request.QueryString,The ID that you can decide this file is the user wants editorial.Your need inputs a few information for the record from inside the database and show them go up in screen.The ID in the database and whole model about the same,Particularly,If you are in,that area used AutoNumber property.The ID that you input is one is strung together in fact.Because of this,Unless you are changed into same kind,these two match impossibly forever.
Request.QueryString:
Use FileSystemObject, you can test a text version, for instance, *.html, *.asp, *.inc. , *.gif, or the existence of catalog.If the file exists,You can want a chain of time to happen.If the file is nonexistent,You may need other event to happen,Use the code below:%26lt;%
SPath="/profiles/" %26 StrFileName %26 ".asp "
SFile=Server.MapPath(sPath)
Set Fe=Server.CreateObject("Scripting.FileSystemObject" )
If Fe.FileExists(sFile) THEN
'do Something
Response.Write "Yeah! I Found It! . ..
Response.Write "You Can Access That File By "
Response.Write %26quot;%26lt;A HREF=%26quot;%26quot;%26quot; %26amp; SPath %26amp; %26quot;%26quot;%26quot;%26gt;Clicking Here%26lt;/A%26gt; . Response.Write "Clicking Here ..
Else
'do Something
Response.Write "Sorry. The Requested File Does Not Exist. The Requested File Does Not Exist..
End If
%%26gt;
To check you simply this file,Add script to most above:
StrFileName = "name "
' First Assign The Name Of A File You Have To This Variable.
' StrFileName Holds Just The Name, not The Extension Or The Path.
' Make Sure You Change The Path For SPath To The Virtual Directory Your File Is In
' Run The Script.
' Then Come Back And Change The StrFileName Variable To The Name Of A File
' You Do NOT Have.
' Run The Script.
The change is rectified for by the code of the input model it is very easy and can make you the following the job becomes a bit easier,The format of example is such:
%26lt;%
Dim IntUserID IntUserID = Request.QueryString("userID" )
IntUserID = CInt(intUserID)
' IntUserID Is Now An Integer.
%%26gt;
You are same OK also your ASP code uses explanatory note they.
Annotate code
In ASP,A script is sent in it be carried out before the browser,So,You do not need to use common HTML annotate label to conceal script from old browser.In fact,Your script won't show in HTML source,Was handed in to go out by the browser because of that source code,So,Old browser won't be abrupt launch any code to arrive on screen.
You may want annotate to come annotate your ASP script,In VB script,You can be used omit accord with will record explanatory note:
%26lt;%
Currentdate = Now
' Make Sure You Use Quotation Marks Around The HTML Code
' The %26 Serves To Concatenate The String
Response.Write "Today Is: %26quot;%26amp; Currentdate %26amp; %26quot;%26lt;BR%26gt; %26quot;
%%26gt;
Use in ASP script / / will represent explanatory note
Use include
If you had used.shtml document before,You may have been familiar with included working course,If do not have,We will tell you how to be used step by step.
One is included is a capacity,Its memory is in an alone file.In standard HTML,Include use.inc is normally patulous.In ASP,Your use.asp,.txt or.inc patulous name.Then you will call a file to arrive in HTML code.Be sent when HTML file,The content that contains a file to come out and be written to screen to serve as HTML directly from inside special file.Because of this,If you do source code of a view,What the indication page that you see and you input is same result.
To a common HTML,When founding a stencil for the site,Its can a lot of more economic time.The head,Page foot and navigation element are to show in you the one part in a large number of pages.Use when you when including,You are about to input a file and call it when need.This has a few advantages:
When updating content,You need to replace a document only.
Including Meat is from what keep apart in HTML page,So anybody wants to be made to content revise can avert littery scenario.
Your core HTML file is less and more practical.
In ASP,Including is impayable.You are OK over and over use script,Even a few moment can string together so simple memory like a join in include,And,It can be deleted in the page that cannot use.
Include a file to use,The random that you use these forms:
%26lt; ! - - #INCLUDE FILE="filename.inc "- - %26gt;
Or
%26lt; ! - - #INCLUDE VIRTUAL="/filename.inc "- - %26gt; .
The file cites include used relevant method.VIRTUAL cites an absolutely method arrives on relevant server.If you consider mobile catalog and file,The simplest method is acquiesce use VIRTUAL,Such mistakes that later you won't encounter a few expect to be less than.Additional on one hand,When you check a file,You need to use a document,Because he relies on the individual server that how you install.
In standard HTML,You include a file to use.inc to yours commonly suffixal.In ASP,You can use.asp.This file that can avoid you is OK easily other is opened and do not read.