[摘要]访问者每次进来都看到是同一幅图片,是不是显得有些单凋?让访问者每来一次看到不同的图片?用计数器就很简单地实现了!源程序如下: <% '-------------------------...
访问者每次进来都看到是同一幅图片,是不是显得有些单凋?
让访问者每来一次看到不同的图片?用计数器就很简单地实现了!
源程序如下:
 <% 
'----------------------------------------------------------计数程序开始
dim fileobject,countfile,out,counter,picno,pp
Set FileObject=Server.CreateObject("Scripting.FileSystemObject") 
CountFile=Server.MapPath("count.txt")
Set Out=FileObject.OpenTextFile(CountFile,1,FALSE,FALSE) 
counter=Out.ReadLine 
Out.Close 
SET FileObject=Server.CreateObject("Scripting.FileSystemObject") 
Set Out=FileObject.CreateTextFile(CountFile,TRUE,FALSE) 
Application.lock 
counter= counter + 1
'----------------------------------------------------------计数程序结束
if counter>99 then counter=0                '不能超过某个值,这个地 
                                  方你注意了,不能跟显示的数字变量一样:(
if counter<10 then                   '我现在只有10张图片,10以下是 
                                                   '多 少就显示多少
picno=counter
else
picno=(counter mod 10)         '大于10只取个位,因为我一共只有10
                                                 张 图片:(
end if
Out.WriteLine(counter)       '把当前的计数值存在counter.txt里面
Application.unlock 
Out.Close
%>
本例所用的存计数值的方法是用的文本文件进行存取
显示图片
<%response.write("<img src=http://cfan.net.cn/info/"&"images/face/face"&picno&".jpg width=229 height=160>")%>  
关键词:计数器的另一用法:自动切换首页图片