Open Statement

Malfermas datuman kanalon.

Sintakso:

Open FileName As String [For Mode] [Access IOMode] [Protected] As [#]FileNumber As Integer [Len = DatasetLength]

Parametroj:

FileName: Name and path of the file that you wan to open. If you try to read a file that does not exist (Access = Read), an error message appears. If you try to write to a file that does not exist (Access = Write), a new file is created.

Mode: Keyword that specifies the file mode. Valid values: Append (append to sequential file), Binary (data can be accessed by bytes using Get and Put), Input (opens data channel for reading), Output (opens data channel for writing), and Random (edits relative files).

IOMode: Ŝlosila vorto kiu difinas la aliran tipon. Validaj valoroj: Read (nurlega), Write (nurskriba), Read Write (ambaŭ).

Protected: Ŝlosila vorto kiu difinas la sekurecan staton de dosiero malferminte ĝin. Validaj valoroj: Shared (aliaj aplikaĵoj povas malfermi ĝin), Lock Read (dosiero estas protektata kontraŭ legado), Lock Write (dosiero estas protektata kontraŭ skribado), Lock Read Write (malpermesas aliri la dosieron).

FileNumber: Entjera esprimo de 0 ĝis 511, por indiki la nombron de libera datuma kanalo. Oni povas pasi komandojn tra la kanalo por aliri dosieron. La dosieran numeron devas atribui la funkcio FreeFile tuj antaŭ la ordono Open.

DatasetLength: Por senvice atingeblaj dosieroj, agordu la longon de la rikordoj.

Note Icon

Eblas modifi la enhavon de dosiero nur se tiu dosiero estas malfermita per la ordono Open. Se oni provas malfermi dosieron jam malfermitan, aperos prierara mesaĝo.


Ekzemplo:

Sub ExampleWorkWithAFile

Dim iNumber As Integer

Dim sLine As String

Dim aFile As String

Dim sMsg As String

    aFile = "c:\data.txt"

    iNumber = Freefile

    Open aFile For Output As #iNumber

    Print #iNumero, "Jen linio de teksto"

    Print #iNumero, "Jen alia linio de teksto"

    Close #iNumber

    iNumber = Freefile

    Open aFile For Input As iNumber

    While Not eof(iNumber)

        Line Input #iNumber, sLine

        If sLine <>"" Then

            sMsg = sMsg & sLine & chr(13)

        End If

    Wend

    Close #iNumber

    MsgBox sMsg

End Sub