ASP编程 PHP编程 JSP编程 NET编程 CGI编程 XML编程 
Google adsense申请技巧本站核心代理域名注册主机业务 快速发布你的买卖域名买卖网站信息 1元注册 cn域名
站长每日新闻导读 √ ·推荐万网空间¥120元 150m 站长网:站长必上的网站网站联盟大全本站代理万网域名55空间120元
 2007-9-26 12:51:08

使用ASP脚本技术

来源: 字体:[ ]

<% strName = Request.Form("Name")
strCheckName = "Amy Cowen"
If strName = strCheckName THEN
Response.Write "Success! The names matched."
Else
Response.Write "Sorry. The names do not match."
End if
%>

如果strName的值是 " Amy Cowen",因为那个是我怎样将它输入到形式box中,然后测试两个变量是否一样,结果不是,因为 "Amy Cowen" 不是" Amy Cowen."

同样地,如果你将Name输入到URL中:

<% Response.Write " & objRec("Name") & "">Your Site" %>

如果Name中的记录的任何部分有额外的空间,你将迅速的执行错误问题。

你可以修正一整个串后者在左边或者右边执行进程:

<% strComments = Request.Form("Comments")
strComments = Trim(strComments)
%>

假定用户已经输入::

" I am having problems installing the software I downloaded. "

上面的修整语句将会打散额外的空间,只留下下面的内容:

"I am having problems installing the software I downloaded."

现在,回到我们的 " Amy Cowen" 例子,如果我添加了下面的脚本,我们就会成功:

strName = Trim(strName)

在右边修整, 使用Rtrim(string). 在左边修整, 使用Ltrim(string).

转换
当你开始使用和VB差不多的语言的时候,你会犯一些简单的错误,比如比较整型的512和串512。如果你认识到前一个512和后一个512是不一样的,你可以想想为什么给出的脚本不能正常工作。

假想一下,你传送一个文件的ID到ASP脚本中,使用Request.QueryString,你会确定这个文件的ID就是用户想要编辑的。你需要从数据库中为记录输入一些信息并将它们显示在屏幕上。数据库中的ID和整型差不多,特别地,如果你在那个区域使用了AutoNumber性能。你输入的ID事实上是一个串。因此,这两个永远不可能匹配除非你转换成相同的类型。

Request.QueryString:
使用FileSystemObject, 你可以测试一个文本—比如, *.html, *.asp, *.inc., *.gif—或者目录的存在。如果文件存在,你可以想要一连串的时间发生。如果文件不存在,你可能需要其他的事件发生,使用下面的代码: <%
    sPath="/profiles/" & strFileName & ".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 "<A HREF=""" & sPath & """>Clicking Here</A>."
    else
      'do something
      Response.Write "Sorry. The requested file does not exist."
    end if
%>

为了简单的测试你这个文件,添加脚本到最上面:

    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.

 

网站地图 - 域名注册续费虚拟主机代理 - 交易论坛 - 网站投稿 - 广告服务 - 帮助中心 - 联系我们
Copyright ©2003-2007 www.Admin5.com All Rights Reserved