Bookshelf Home | Contents | Index | Search | PDF |
Siebel VB Language Reference > Siebel VB Language Reference >
Get Statement
This standard VB function reads data from a file opened in Random or Binary mode and puts it in a variable.
Syntax
Get [#]filenumber, [recnumber], varName
Returns
Not applicable
Usage
For more information about how files are numbered when they are opened, read Open Statement.
The Recnumber argument is in the range 1 to 2,147,483,647. If this argument is omitted, the next record or byte is read.
NOTE: The commas before and after the recnumber are required, even if you do not supply a recnumber.
For Random mode, the following rules apply:
Blocks of data are read from the file in chunks whose size is equal to the size specified in the Len clause of the Open statement. If the size of varName is smaller than the record length, the additional data is discarded. If the size of varName is larger than the record length, an error occurs.
For variable length string variables, Get reads two bytes of data that indicate the length of the string, then reads the data into varName.
For variant variables, Get reads two bytes of data that indicate the type of the variant, then it reads the body of the variant into varName. Note that variants containing strings contain two bytes of data type information followed by two bytes of length followed by the body of the string.
User defined types are read as if each member were read separately, except no padding occurs between elements.
Files opened in Binary mode behave similarly to those opened in Random mode, except that:
- Get reads variables from the disk without record padding.
- Variable-length Strings that are not part of user-defined types are not preceded by the two-byte string length. Instead, the number of bytes read is equal to the length of varName.
Example
This example opens a file for Random access, gets its contents, and closes the file again. The second subprogram,
createfile
, creates thec:\temp001
file 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 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 SubSee Also
Bookshelf Home | Contents | Index | Search | PDF |
Siebel VB Language Reference Published: 18 June 2003 |