<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=shift_jis"> <title>Textカウンター</title> <body> <font SIZE="+2"><b>カウンター</b></font><br> <% On Error Resume Next Set objFile = Server.CreateObject("Scripting.FileSystemObject") sPathCountFile = Server.MapPath("/userid/_exc\textcount.txt") Set strmFile = objFile.OpenTextFile(sPathCountFile, 1, FALSE)
If Err <> 0 Then Select Case Err Case 53 Set strmFile = objFile.CreateTextFile(sPathCountFile,False,False) strmFile.WriteLine 0 strmFile.Close Set strmFile = objFile.OpenTextFile(sPathCountFile, 1, FALSE) Err.Clear Case Else Response.Write("エラー元: " & Err.Source & "<BR>") Response.Write("エラー番号: " & Err.Number & "<BR>") Response.Write("エラーの説明: " & Err.Description & "<BR>") Err.Clear End Select End if
If Err.Number > 0 Then iCount = 0 Else iCount = strmFile.ReadLine End If iCount = iCount + 1 strmFile.Close Set strmFile = objFile.OpenTextFile(sPathCountFile, 2, TRUE) strmFile.WriteLine iCount strmFile.Close sCount = right("000000" & CSTR(iCount), 6) 'sCountを使用すると頭に0が付加されます。 Response.Write sCount Response.Write "<br>" 'iCountを使用すると数字だけ表示されます。 Response.Write iCount Response.Write "<br><br>↑0を付けた表示、数字だけの表示いずれかを使用できます。" %> </body> </html>