Kan man minska ner denna koden? <code> Den klagar på: Vad sätter du file variabeln till. Fanns nämligen ingen rad som satte den i det första scriptet så jag gissar på att det är den som spökar. Annars kan du ju skriva ut filname variabeln. Nu funkar det igen, file är lika med index som default, annars beror det på...Kan man minska ner koden?
<code>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="20%">
<%
' Declare variables for the File System Object and the File to be accessed.
Dim objFSO, objTextFile
' Create an instance of the the File System Object and assign it to objFSO.
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Open the file
Set objTextFile = objFSO.OpenTextFile(Server.MapPath("vanster.txt"))
Do While Not objTextFile.AtEndOfStream
Response.Write objTextFile.ReadLine & "<br>" & vbCrLf
Loop
' Close the file.
objTextFile.Close
' Release reference to the text file.
Set objTextFile = Nothing
' Release reference to the File System Object.
Set objFSO = Nothing
%>
</td>
<td width="5%"> </td>
<td width="60%">
<%
' Create an instance of the the File System Object and assign it to objFSO.
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Open the file
Set objTextFile = objFSO.OpenTextFile(Server.MapPath(file + ".txt"))
Do While Not objTextFile.AtEndOfStream
Response.Write objTextFile.ReadLine & "<br>" & vbCrLf
Loop
' Close the file.
objTextFile.Close
' Release reference to the text file.
Set objTextFile = Nothing
' Release reference to the File System Object.
Set objFSO = Nothing
%>
</td>
<td width="5%"> </td>
<td width="20%">
<%
' Create an instance of the the File System Object and assign it to objFSO.
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Open the file
Set objTextFile = objFSO.OpenTextFile(Server.MapPath("hoger.txt"))
Do While Not objTextFile.AtEndOfStream
Response.Write objTextFile.ReadLine & "<br>" & vbCrLf
Loop
' Close the file.
objTextFile.Close
' Release reference to the text file.
Set objTextFile = Nothing
' Release reference to the File System Object.
Set objFSO = Nothing
%>
</td>
</tr>
</table>
</code>Sv: Kan man minska ner koden?
<%
' Declare variables for the File System Object and the File to be accessed.
Dim objFSO
' Create an instance of the the File System Object and assign it to bjFSO.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Sub WriteFile(FileName, objFSO)
Dim objTextFile
' Open the file
Set objTextFile = objFSO.OpenTextFile(FileName)
Do Until objTextFile.AtEndOfStream
Response.Write objTextFile.ReadLine & "<br>" & vbCrLf
Loop
' Close the file.
objTextFile.Close
' Release reference to the text file.
Set objTextFile = Nothing
End Sub
%>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="20%">
<% WriteFile Server.MapPath("vanster.txt"), objFSO %>
</td>
<td width="5%"> </td>
<td width="60%">
<% WriteFile Server.MapPath(file + ".txt"), objFSO %>
</td>
<td width="5%"> </td>
<td width="20%">
<% WriteFile Server.MapPath("hoger.txt"), objFSO %>
</td>
</tr>
</table>
<%
' Release reference to the File System Object.
Set objFSO = Nothing
%>
</code>Sv: Kan man minska ner koden?
<code>
' Open the file
Set objTextFile = objFSO.OpenTextFile(FileName)
</code>
Feltyp:
Körningsfel i Microsoft VBScript (0x800A0035)
Det går inte att hitta filen.
/nyakl/Default.asp, line 25
Och jag förstår den ;)
Men vad ska jag skriva? Det är ju olika för varje gång...Sv: Kan man minska ner koden?
Sv: Kan man minska ner koden?
Men kruxet var att den hittade ingen index.txt-fil, men nu finns det en :)