Bookshelf Home | Contents | Index | Search | PDF |
Siebel VB Language Reference > Siebel VB Language Reference >
Open Statement
This standard VB statement opens a file for input or output.
Syntax
Open filename [For mode] [Access access] [lock] As [#]filenumber [Len = reclen]
Returns
A file opened in the specified manner.
NOTE: The file opens in the default code page of the local operating system. File I/O does not support Unicode.
Usage
The following keywords are used for mode, access, and lock:
A file must be opened before any input/output operation can be performed on it.
If filename does not exist, it is created when opened in append, binary, output, or random modes.
If mode is not specified, it defaults to random.
If access is not specified for random or binary modes, access is attempted in the following order: Read Write, Write, Read.
If lock is not specified, filename can be opened by other processes that do not specify a lock, although that process cannot perform any file operations on the file while the original process still has the file open.
Use the FreeFile function to find the next available value for filenumber.
The reclen parameter is ignored for Input, Output, and Append modes.
Example
This example opens a file for random access, gets the contents of the file, and closes the file again. The second subprogram,
CreateFile
, creates the filec:\temp001
used by the main subprogram.(general) (declarations)
Option Explicit
Declare Sub CreateFileSub CreateFile
' Put the numbers 1-10 into a file
Dim x as Integer
Open "c:\temp001" for Output as #1
For x = 1 to 10
Write #1, x
Next x
Close #1
End SubSub Button_Click
Dim acctno as String * 3
Dim recno as Long
Dim msgtext as String
Call CreateFile
recno = 1
newline = Chr(10)
Open "c:\temp001" For Random As #1 Len = 3
msgtext = "The account numbers are:" & newline
Do Until recno = 11
Get #1,recno,acctno
msgtext = msgtext & acctno
recno = recno + 1
Loop
Close #1
Kill "c:\temp001"
End SubSee Also
Bookshelf Home | Contents | Index | Search | PDF |
Siebel VB Language Reference Published: 18 June 2003 |