Siebel VB Language Reference > Methods Reference for Siebel VB > File Control Methods >

Open File Method


The Open File method opens a file for input or output. It does not return a value. Siebel CRM opens the file in the default character encoding that the local operating system uses. This method does not support Unicode.

Format

Open filename [For mode] [Access access] [lock] As [#]filenumber [Len = reclen]

The following table describes the arguments that you can use with this method.

Argument
Description

filename

A string or string expression that identifies the name of the file to open. If this file does not exist, then this method creates it if opened in one of the following modes:

  • Append
  • Binary
  • Output
  • Random Modes

This file must be open before Siebel VB can perform any input or output operation on it.

mode

A keyword that identifies the purpose for which this method opens the file. If you do not include the mode argument, then this method defaults the mode to random.

access

A keyword that identifies the method to access the file. If you do not include the access argument for random or binary modes, then the Open File method attempts to access the file in the following order:

  1. Read Write
  2. Write
  3. Read

lock

A keyword that designates the access method that other processes can use to open this file. If you do not include the lock argument, then other processes can open the file that the filename argument identifies. Other processes cannot perform any file operation on the file while the original process still has the file open.

filenumber

An integer that identifies the file while it is open. You can use the Get Free File Number method to find the next available value that you can use in the filenumber argument. For more information, see Get Free File Number Method.

reclen

In a random or binary file, the length of the records. This method ignores the reclen argument for the following modes:

  • Input
  • Output
  • Append
Usage

The following table describes the keywords that you can use with this method.

Type of Keyword
Keyword
Description

Mode

Input

Reads data from the file sequentially.

Output

Puts data into the file sequentially.

Append

Adds data to the file sequentially.

Random

Gets data from the file by random access.

Binary

Gets binary data from the file.

Access

Read

Reads data only from the file.

Write

Writes data only to the file.

Read Write

Reads or writes data to the file.

Lock

Shared

Read or write is available on the file.

Lock Read

Only read is available.

Lock Write

Only write is available.

Lock Read Write

No read or write is available.

Example

The following example opens a file for random access, gets the contents of the file, and then closes the file. The CreateFile subroutine creates the c:\temp001 file that the main subroutine uses:

(general) (declarations)
Option Explicit
Declare Sub CreateFile

Sub 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 Sub

Sub 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 Sub

Siebel VB Language Reference Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Legal Notices.