Siebel VB Language Reference > Methods Reference for Siebel VB > File Input and Output Methods >

Get File Contents Method


The Get File Contents method reads the content of a file opened in random or binary mode, and then places this content in a variable. It does not return a value.

Format

Get [#]filenumber, [recnumber], varName

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

Argument
Description

filenumber

The file number that the Open statement uses to open the file. For information about how Siebel VB numbers a file when it opens a file, see Open File Method.

recnumber

An expression of type long. It contains a value that depends on one of the following modes:

  • Random mode. The record number at which to start reading.
  • Binary mode. The byte offset at which to start reading.

The recnumber argument is in the range of 1 through 2,147,483,647. If you do not include this argument, then this method uses the next record or byte.

You must include the commas before and after the recnumber argument even if you do not include the recnumber argument.

varName

The name of a variable. This method reads file data into this variable. It can be any variable type except for the following:

  • Object.
  • Array. You can use a single array element.
Usage with Random Mode

For Random mode, the Get File Contents method reads content from the file in chunks whose size is equal to the size specified in the Len clause of the Open statement. It does one of the following, depending on the size of the variable that the varName argument identifies:

  • The variable is smaller than the record length. It discards the additional content.
  • The variable is larger than the record length. It creates an error.

The Get File Contents method handles content differently depending on the following type of variable:

  • Variable length string variable. it reads two bytes of content that identifies the length of the string, and then copies the contents into the variable that the varName argument identifies.
  • Variant variable. It reads two bytes of content that identifies the type of the variant, and then it copies the body of the variant into the varName argument. A variant that includes a string includes the following information:
    1. Two bytes of data type information.
    2. Two bytes of length data.
    3. The body of the string.
  • Custom variable. It reads the content as if each member were read separately. No padding occurs between elements.
Usage with Binary Mode

Usage with a file opened in Binary mode is the same as usage with a file opened in Random mode except for the following differences:

  • The Get File Contents method reads variables from the disk without record padding.
  • For a variable length string that is not part of a custom type, the Get File Contents method does not precede this variable with a two-byte string length. Instead, it reads the number of bytes as equal to the length of the variable that the varName identifies.
Example

The following example opens a file for random access, gets the contents of this 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 Button1_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

Related Topics

Create Function Method

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