This article will share with you some source code that is often used in ASP programming. Suitable for beginners to read. I hope it will be helpful to you, let’s take a look together!
ASP is the abbreviation of Active Server Page, meaning dynamic server page. ASP is an application developed by Microsoft to replace CGI scripting programs. It can interact with databases and other programs and is a simple and convenient programming tool. Continued with the previous article>> http://www.vevb.com/kaifa/asp/70602.html
11.ACCESS database connection:
- <%
- optionexplicit
- dimstartime, endtime,conn,connstr,db
- starttime=timer()
- 'Change the database name
- db=data/dvBBS5.mdb
- Setconn=Server.CreateObject(ADODB.Connection)
- connstr=Provider=Microsoft.Jet.OLEDB.4.0;DataSource=&Server.MapPath(db)
- 'If your server uses an older version of Access driver, please use the following connection method
- 'connstr=driver={Microsoft AccessDriver(*.mdb)};dbq=&Server.MapPath(db)
- conn.Openconnstr
- functionCloseDatabase
- Conn.close
- Setconn=Nothing
- EndFunction
- %>
12.SQL database connection:
- <%
- optionexplicit
- dimstartime, endtime,conn,connstr,db
- starttime=timer()
- connstr=driver={SQLServer};server=HUDENQ-N11T33NB;uid=sa;pwd=xsfeihu;database=dvbbs
- Setconn=Server.CreateObject(ADODB.Connection)
- conn.Openconnstr
- functionCloseDatabase
- Conn.close
- Setconn=Nothing
- EndFunction
- %>
13. Open the web page code with the keyboard:
- <scriptlanguage=javascript>
- functionctlent(eventobject)
- {
- if((event.ctrlKey&&window.event.keyCode==13)||(event.altKey&window.event.keyCode==83))
- {
- window.open('website','','')
- }
- }
- </script>
Here is the codes of Ctrl+Enter and Alt+S by yourself and then change them.
14. Make the layer not overwritten by the control code:
- <divz-Index:2><objectxxx></object></div>#Front
- <divz-Index:1><objectxxx></object></div>#Back
- <divid=Layer2style=position:absolute;top:40;width:400px;height:95px;z-index:2>
- <tableheight=100%width=100%bgcolor=#ff0000><tr>
- <tdheight=100%width=100%></td></tr></table><iframewidth=0height=0></iframe></div>
- <divid=Layer1style=position:absolute;top:50;width:200px;height:115px;z-index:1>
- <iframeheight=100%width=100%></iframe></div>
15.Dongwang FLASH advertising code:
- <objectclassid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000
- codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0
- width=468height=60>
- <paramname=movievalue=images/yj16d.swf>
- <paramname=qualityvalue=high>
- <embedsrc=images/dvbanner.swfquality=high
- pluginspage=http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash;
- ;;;;;;;;;;;;; type=application/x-shockwave-flashwidth=468height=60></embed></object>
16.VBS popup window code:
- <scriptlanguage=vbscript>
- msgbox you have not registered or logged in to the forum, 0, boutique forum
- location.href=login.asp
- </script>
17. Use FSO to modify file-specific content functions:
- functionFSOchange(filename,Target,String)
- DimobjFSO, objCountFile, FiletempData
- SetobjFSO=Server.CreateObject(Scripting.FileSystemObject)
- SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(filename),1,True)
- FiletempData=objCountFile.ReadAll
- objCountFile.Close
- FiletempData=Replace(FiletempData,Target,String)
- SetobjCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)
- objCountFile.WriteFiletempData
- objCountFile.Close
- SetobjCountFile=Nothing
- SetobjFSO=Nothing
- EndFunction
18. Functions that use FSO to read file content:
- functionFSOFileRead(filename)
- DimobjFSO, objCountFile, FiletempData
- SetobjFSO=Server.CreateObject(Scripting.FileSystemObject)
- SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(filename),1,True)
- FSOFileRead=objCountFile.ReadAll
- objCountFile.Close
- SetobjCountFile=Nothing
- SetobjFSO=Nothing
- EndFunction
19. Functions that use FSO to read a certain line of a file:
- functionFSOlinedit(filename,lineNum)
- iflinenum<1thenexitfunction
- dimfso,f,temparray,tempcnt
- setfso=server.CreateObject(scripting.filesystemobject)
- ifnotfso.fileExists(server.mappath(filename))thenexitfunction
- setf=fso.opentextfile(server.mappath(filename),1)
- ifnotf.AtEndofStreamthen
- tempcnt=f.readall
- f.close
- setf=nothing
- template=split(tempcnt,chr(13)&chr(10))
- iflineNum>ubund(temparray)+1then
- exitfunction
- else
- FSOlinedit=temparray(lineNum-1)
- endif
- endif
- endfunction
20. Functions that modify file-specific content using FSO:
- functionFSOchange(filename,Target,String)
- DimobjFSO, objCountFile, FiletempData
- SetobjFSO=Server.CreateObject(Scripting.FileSystemObject)
- SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(filename),1,True)
- FiletempData=objCountFile.ReadAll
- objCountFile.Close
- FiletempData=Replace(FiletempData,Target,String)
- SetobjCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)
- objCountFile.WriteFiletempData
- objCountFile.Close
- SetobjCountFile=Nothing
- SetobjFSO=Nothing
- EndFunction
21. Functions that use FSO to read file contents
:
- functionFSOFileRead(filename)
- DimobjFSO, objCountFile, FiletempData
- SetobjFSO=Server.CreateObject(Scripting.FileSystemObject)
- SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(filename),1,True)
- FSOFileRead=objCountFile.ReadAll
- objCountFile.Close
- SetobjCountFile=Nothing
- SetobjFSO=Nothing
- EndFunction
22. Functions that use FSO to read a certain line of a file:
- functionFSOlinedit(filename,lineNum)
- iflinenum<1thenexitfunction
- dimfso,f,temparray,tempcnt
- setfso=server.CreateObject(scripting.filesystemobject)
- ifnotfso.fileExists(server.mappath(filename))thenexitfunction
- setf=fso.opentextfile(server.mappath(filename),1)
- ifnotf.AtEndofStreamthen
- tempcnt=f.readall
- f.close
- setf=nothing
- template=split(tempcnt,chr(13)&chr(10))
- iflineNum>ubund(temparray)+1then
- exitfunction
- else
- FSOlinedit=temparray(lineNum-1)
- endif
- endif
- endfunction
At this point, I will introduce it to you in the summary of commonly used ASP codes. I hope it will be helpful to you.