/ Forside / Teknologi / Udvikling / ASP / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
ASP
#NavnPoint
smorch 9259
Harlekin 1866
molokyle 1040
Steffanst.. 758
gandalf 657
smilly 564
gibson 560
cumano 530
MouseKeep.. 480
10  Random 410
asp output til .txt fil
Fra : pta


Dato : 22-09-05 10:40

Hej

asp scriptet nedenfor fungerer fint som hit counter. Variabelen
"iCount" gemmes i en .txt fil "count.txt". Jeg gerne have .asp
filen til at skrive "hits=" lige inden "iCount" i txt filen.

Nogle bud på hvordan det kan gøres?


<%
' Declare our vaiables
Dim objFSO, objCountFile ' object vars for FSO and File
Dim strCountFileName ' filename of count text file
Dim iCount ' count variable
Dim bUseImages ' boolean whether or not to use images
Dim I ' standard looping var


' Determine whether we use images or plain text
' You could just set this to True or False instead
bUseImages = False

' Compute our count file's filename
strCountFileName = Server.MapPath("count.txt")


' Create FileSystemObject to deal with file access
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

' Open the file as a text stream (1 = ForReading, True = Create)
Set objCountFile = objFSO.OpenTextFile(strCountFileName, 1, True)

' Read the current count from the file
If Not objCountFile.AtEndOfStream Then
' Set value to contents of the file
iCount = CLng(objCountFile.ReadAll)
Else
' If no file exists or it's empty start at 0
iCount = 0
End If

' Close the file and destroy the object
objCountFile.Close
Set objCountFile = Nothing


' Increment the count
iCount = iCount + 1


' Overwrite existing file and get a text stream to new one
Set objCountFile = objFSO.CreateTextFile(strCountFileName, True)

' Write updated count
objCountFile.Write iCount

' Close the file and destroy the object
objCountFile.Close
Set objCountFile = Nothing


' Destroy the FSO object
Set objFSO = Nothing


' We're all done with the hard part
' All that's left is to display the results
If bUseImages Then
' Loop through the count integer showing each digit
' You can grab the images one at a time or get the zip
' http://www.asp101.com/samples/download/counter_imgs.zip
For I = 1 to Len(iCount)
' Output the IMG tag using the right digit
Response.Write "<img src=""./images/digit_"
Response.Write Mid(iCount, I, 1)
Response.Write ".gif"" alt="""
Response.Write Mid(iCount, I, 1)
Response.Write """ width=""20"" height=""27"" />"
Next 'I
Else
' No image wanted just show the variable
Response.Write iCount
End If
%>

--
Vil du lære at kode HTML, XHTML, CSS, SSI, ASP eller ASP.NET?
- Pædagogiske tutorials på dansk
- Kom godt i gang med koderne
KLIK HER! => http://www.html.dk/tutorials

 
 
Jens Gyldenkærne Cla~ (22-09-2005)
Kommentar
Fra : Jens Gyldenkærne Cla~


Dato : 22-09-05 12:00

pta skrev:

> asp scriptet nedenfor fungerer fint som hit counter. Variabelen
> "iCount" gemmes i en .txt fil "count.txt". Jeg gerne have .asp
> filen til at skrive "hits=" lige inden "iCount" i txt filen.

Hvad er formålet? Hvis det er for at vise sætningen "hits=X" på de
sider hvor du bruger tælleren, er det lettere at indsætte "hits="
direkte på disse sider. Men det kan da godt gøres i filen:

Jeg vil foreslå dig at gemme dit præfiks som en konstant - det skal
nemlig bruges både når man læser og når man gemmer filen, og ved at
have det som en konstant, sikrer du at både læsning og skrivning
arbejder med samme præfiks.


Const prefix = "hits="

> ' Read the current count from the file
> If Not objCountFile.AtEndOfStream Then
> ' Set value to contents of the file
> iCount = CLng(objCountFile.ReadAll)

Hvis filen ikke kun indeholder et tal, skal læsningen af tallet
tilrettes:

iCount = CLng(Replace(objCountFile.ReadAll, prefix, ""))


> ' Write updated count
> objCountFile.Write iCount

Her skal præfikset igen sættes ind:

objCountFile.Write prefix & Cstr(iCount)



> ' All that's left is to display the results

Hvis det bare er i udskriften der skal stå hits=X, kan du nøjes med
følgende rettelse:

> Else
> ' No image wanted just show the variable
> Response.Write iCount

Response.write "hits=" & Cstr(iCount)
--
Jens Gyldenkærne Clausen
Svar venligst under det du citerer, og citer kun det der er
nødvendigt for at forstå dit svar i sammenhængen. Se hvorfor og
hvordan på http://usenet.dk/netikette/citatteknik.html

Preben Andersen (22-09-2005)
Kommentar
Fra : Preben Andersen


Dato : 22-09-05 12:15

Tak jens :)

Det var lige det jeg havde brug for.

Skal bruge indlæse txtfilen i Flash og derfor skulle have "hits="
inkluderet i txtfilen.

--
Vil du lære at kode HTML, XHTML, CSS, SSI, ASP eller ASP.NET?
- Pædagogiske tutorials på dansk
- Kom godt i gang med koderne
KLIK HER! => http://www.html.dk/tutorials

Preben Andersen (22-09-2005)
Kommentar
Fra : Preben Andersen


Dato : 22-09-05 12:17

Tak jens

Det var præcis hvad jeg havde brug for.

Txtfilen skal indlæses i Flash og derfor skulle "hits=" inkluderes i
txtfilen.

--
Vil du lære at kode HTML, XHTML, CSS, SSI, ASP eller ASP.NET?
- Pædagogiske tutorials på dansk
- Kom godt i gang med koderne
KLIK HER! => http://www.html.dk/tutorials

Søg
Reklame
Statistik
Spørgsmål : 177500
Tips : 31968
Nyheder : 719565
Indlæg : 6408518
Brugere : 218887

Månedens bedste
Årets bedste
Sidste års bedste