ASP常用源代码的总结(下)

ASP教程 2025-08-06

本文再和大家分享一些ASP程序设计中经常用到的源代码。适合初学者阅读。希望对你有帮助,一起来看吧!

ASP是Active Server Page的缩写,意为动态服务器页面。ASP是微软公司开发的代替CGI脚本程序的一种应用,它可以与数据库和其它程序进行交互,是一种简单、方便的编程工具。接上篇>>http://www.**v*evb.com/kaifa/asp/70602.html

11.ACCESS数据库连接:

  1. <%
  2. optionexplicit
  3. dimstartime,endtime,conn,connstr,db
  4. startime=timer()
  5. '更改数据库名字
  6. db=data/dvBBS5.mdb
  7. Setconn=Server.CreateObject(ADODB.Connection)
  8. connstr=Provider=Microsoft.Jet.OLEDB.4.0;DataSource=&Server.MapPath(db)
  9. '如果你的服务器采用较老版本Access驱动,请用下面连接方法
  10. 'connstr=driver={MicrosoftAccessDriver(*.mdb)};dbq=&Server.MapPath(db)
  11. conn.Openconnstr
  12. functionCloseDatabase
  13. Conn.close
  14. Setconn=Nothing
  15. EndFunction
  16. %>

12.SQL数据库连接:

  1. <%
  2. optionexplicit
  3. dimstartime,endtime,conn,connstr,db
  4. startime=timer()
  5. connstr=driver={SQLServer};server=HUDENQ-N11T33NB;uid=sa;pwd=xsfeihu;database=dvbbs
  6. Setconn=Server.CreateObject(ADODB.Connection)
  7. conn.Openconnstr
  8. functionCloseDatabase
  9. Conn.close
  10. Setconn=Nothing
  11. EndFunction
  12. %>

13.用键盘打开网页代码:

  1. functionctlent(eventobject)
  2. {
  3. if((event.ctrlKey&&window.event.keyCode==13)||(event.altKey&&window.event.keyCode==83))
  4. {
  5. window.open('网址','','')
  6. }
  7. }

这里是Ctrl+Enter和Alt+S的代码 自己查下键盘的ASCII码再换就行

14.让层不被控件复盖代码:

#前面
  • #后面
  • 15.动网FLASH广告代码:

    1. codebase=http://download.*macr*om*edia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0
    2. width=468height=60>
    3. pluginspage=http://www.m*acr**omedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash;
    4. ;;;;;;;;;;;type=application/x-shockwave-flashwidth=468height=60>

    16.VBS弹出窗口小代码:

    1. msgbox你还没有注册或登陆论坛,0,精品论坛
    2. location.href=login.asp

    17.使用FSO修改文件特定内容的函数:

    1. functionFSOchange(filename,Target,String)
    2. DimobjFSO,objCountFile,FiletempData
    3. SetobjFSO=Server.CreateObject(Scripting.FileSystemObject)
    4. SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(filename),1,True)
    5. FiletempData=objCountFile.ReadAll
    6. objCountFile.Close
    7. FiletempData=Replace(FiletempData,Target,String)
    8. SetobjCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)
    9. objCountFile.WriteFiletempData
    10. objCountFile.Close
    11. SetobjCountFile=Nothing
    12. SetobjFSO=Nothing
    13. EndFunction

    18.使用FSO读取文件内容的函数:

    1. functionFSOFileRead(filename)
    2. DimobjFSO,objCountFile,FiletempData
    3. SetobjFSO=Server.CreateObject(Scripting.FileSystemObject)
    4. SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(filename),1,True)
    5. FSOFileRead=objCountFile.ReadAll
    6. objCountFile.Close
    7. SetobjCountFile=Nothing
    8. SetobjFSO=Nothing
    9. EndFunction

    19.使用FSO读取文件某一行的函数:

    1. functionFSOlinedit(filename,lineNum)
    2. iflinenum<1thenexitfunction
    3. dimfso,f,temparray,tempcnt
    4. setfso=server.CreateObject(scripting.filesystemobject)
    5. ifnotfso.fileExists(server.mappath(filename))thenexitfunction
    6. setf=fso.opentextfile(server.mappath(filename),1)
    7. ifnotf.AtEndofStreamthen
    8. tempcnt=f.readall
    9. f.close
    10. setf=nothing
    11. temparray=split(tempcnt,chr(13)&chr(10))
    12. iflineNum>ubound(temparray)+1then
    13. exitfunction
    14. else
    15. FSOlinedit=temparray(lineNum-1)
    16. endif
    17. endif
    18. endfunction

    20.使用FSO修改文件特定内容的函数:

    1. functionFSOchange(filename,Target,String)
    2. DimobjFSO,objCountFile,FiletempData
    3. SetobjFSO=Server.CreateObject(Scripting.FileSystemObject)
    4. SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(filename),1,True)
    5. FiletempData=objCountFile.ReadAll
    6. objCountFile.Close
    7. FiletempData=Replace(FiletempData,Target,String)
    8. SetobjCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)
    9. objCountFile.WriteFiletempData
    10. objCountFile.Close
    11. SetobjCountFile=Nothing
    12. SetobjFSO=Nothing
    13. EndFunction

    21.使用FSO读取文件内容的函数

    1. functionFSOFileRead(filename)
    2. DimobjFSO,objCountFile,FiletempData
    3. SetobjFSO=Server.CreateObject(Scripting.FileSystemObject)
    4. SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(filename),1,True)
    5. FSOFileRead=objCountFile.ReadAll
    6. objCountFile.Close
    7. SetobjCountFile=Nothing
    8. SetobjFSO=Nothing
    9. EndFunction

    22.使用FSO读取文件某一行的函数:

    1. functionFSOlinedit(filename,lineNum)
    2. iflinenum<1thenexitfunction
    3. dimfso,f,temparray,tempcnt
    4. setfso=server.CreateObject(scripting.filesystemobject)
    5. ifnotfso.fileExists(server.mappath(filename))thenexitfunction
    6. setf=fso.opentextfile(server.mappath(filename),1)
    7. ifnotf.AtEndofStreamthen
    8. tempcnt=f.readall
    9. f.close
    10. setf=nothing
    11. temparray=split(tempcnt,chr(13)&chr(10))
    12. iflineNum>ubound(temparray)+1then
    13. exitfunction
    14. else
    15. FSOlinedit=temparray(lineNum-1)
    16. endif
    17. endif
    18. endfunction

    到此,关于ASP常用代码的总结篇,就为大家介绍完了,希望对大家有帮助。