Avatar billede baitianlong Nybegynder
20. maj 2002 - 14:07 Der er 3 kommentarer og
1 løsning

Skrive / læse i fil

Jeg har skrevet dette script som skulle lægge 1 til en variabel i en txt fil, men den kommer med denne fejl:

Der opstod en Microsoft VBScript-kørselsfejl (0x800A0036)
Filtilstanden er ugyldig

-----------------------------
if (Vwhy = "contact") then
    set fs2 = createobject("scripting.filesystemobject")
    set file = fs2.opentextfile(server.mappath("contact.dat"))
    Contactcount = cint(file.readline)
    Contactcount = Contactcount + 1
    file.writeline(Contactcount)
    file.close
    set fs2 = nothing
end if
Avatar billede a1a1 Novice
20. maj 2002 - 14:16 #1
du skal bruge
opentextfile(server.mappath("contact.dat"), 2, False)


Sub OpenTextFileTest
  Const ForReading = 1, ForWriting = 2, ForAppending = 8
  Dim fso, f
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
  f.Write "Hello world!"
  f.Close
End Sub
Avatar billede a1a1 Novice
20. maj 2002 - 14:17 #2
fra dokumentationen

object.OpenTextFile(filename[, iomode[, create[, format]]])

object

Required. Always the name of a FileSystemObject.

filename

Required. String expression that identifies the file to open.

iomode

Optional. Indicates input/output mode. Can be one of three constants: ForReading, ForWriting, or ForAppending.

create

Optional. Boolean value that indicates whether a new file can be created if the specified filename doesn't exist. The value is True if a new file is created; False if it isn't created. The default is False.

format

Optional. One of three Tristate values used to indicate the format of the opened file. If omitted, the file is opened as ASCII.
Avatar billede a1a1 Novice
20. maj 2002 - 14:19 #3
ups DU skal bruge
du skal bruge
opentextfile(server.mappath("contact.dat"), 8, False

fordi du både vil læse og skrive til/fra filen
Avatar billede baitianlong Nybegynder
25. maj 2002 - 00:04 #4
ok
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester