|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
由于ASP还是一种Script语言所没除了大量使用组件外,没有办法提高其工作效率。它必须面对即时编绎的时间考验,同时我们还不知其背后的组件会是一个什么样的状况;计数器比来很多网友在会商计数器的成绩,偶然看到一篇文章,贴出来以解人人十万火急
一下代码贴在第一页便可
<%
Declareourvaiables
DimobjFSO,objCountFileobjectvarsforFSOandFile
DimstrCountFileNamefilenameofcounttextfile
DimiCountcountvariable
DimbUseImagesbooleanwhetherornottouseimages
DimIstandardloopingvar
Determinewhetherweuseimagesorplaintext
YoucouldjustsetthistoTrueorFalseinstead
bUseImages=CBool(Request.QueryString("images"))
Computeourcountfilesfilename
Thisisbasedonthefilefromwhichyoucallcount.asp
Itbasicallytakesthatnameandappendsa.cntsoIdont
accidentlyoverwriteanyfiles.Ifforsomereasonyouhave
afilenamedscript_name.asp.cntthenchangethisorwatchout!
strCountFileName=Server.MapPath(Request.ServerVariables("SCRIPT_NAME")&".cnt")
CreateFileSystemObjecttodealwithfileaccess
SetobjFSO=Server.CreateObject("Scripting.FileSystemObject")
Openthefileasatextstream(1=ForReading,True=Create)
SetobjCountFile=objFSO.OpenTextFile(strCountFileName,1,True)
Readthecurrentcountfromthefile
IfNotobjCountFile.AtEndOfStreamThen
Setvaluetocontentsofthefile
iCount=CLng(objCountFile.ReadAll)
Else
Ifnofileexistsoritsemptystartat0
iCount=0
EndIf
Closethefileanddestroytheobject
objCountFile.Close
SetobjCountFile=Nothing
Incrementthecount
iCount=iCount+1
Overwriteexistingfileandgetatextstreamtonewone
SetobjCountFile=objFSO.CreateTextFile(strCountFileName,True)
Writeupdatedcount
objCountFile.WriteiCount
Closethefileanddestroytheobject
objCountFile.Close
SetobjCountFile=Nothing
DestroytheFSOobject
SetobjFSO=Nothing
Werealldonewiththehardpart
Allthatsleftistodisplaytheresults
IfbUseImagesThen
Loopthroughthecountintegershowingeachdigit
Youcangrabtheimagesoneatatimeorgetthezip
http://www.asp101.com/samples/download/counter_imgs.zip
ForI=1toLen(iCount)
OutputtheIMGtagusingtherightdigit
Response.Write"<IMGSRC=""./images/digit_"
Response.WriteMid(iCount,I,1)
Response.Write".gif""ALT="""
Response.WriteMid(iCount,I,1)
Response.Write"""WIDTH=""20""HEIGHT=""27"">"
NextI
Else
Noimagewantedjustshowthevariable
Response.WriteiCount
EndIf
%></p>asp可以使用微软的activeX使得网页功能无比强大,不过安全性也较差,而且是基于的windows服务器,所以性能稳定性也一般 |
|