Bookshelf Home | Contents | Index | Search | PDF | ![]() ![]() ![]() ![]() |
Siebel VB Language Reference > Siebel VB Language Reference >
Put Statement
This standard VB statement writes a variable to a file opened in random or binary mode.
Syntax
Put [#]filenumber, [ recnumber], varName
Returns
Not applicable
Usage
Filenumber is the number assigned to the file when it was opened. For more information, read Open Statement.
Recnumber is in the range 1 to 2,147,483,647. If recnumber is omitted, the next record or byte is written.
NOTE: The commas before and after recnumber are required, even if no recnumber is specified.
VarName can be any variable type except object, application data type, or array variables (single array elements can be used).
For random mode, the following conditions apply:
- Blocks of data are written to 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 record is padded to the correct record size. If the size of the variable is larger than the record length, an error occurs.
- For variable length string variables, Put writes two bytes of data that indicate the length of the string and then writes the string data.
- For variant variables, Put writes two bytes of data that indicate the type of the variant; then it writes the body of the variant into the variable. Note that variants containing strings contain two bytes of type information, followed by two bytes of length, followed by the body of the string.
- User-defined types are written as if each member were written separately, except no padding occurs between elements.
Files opened in binary mode behave similarly to those opened in random mode except:
- Put writes variables to 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.
NOTE: The Put statement uses the default code page of the local operating system. It does not write to the file in Unicode format.
Example
This example opens a file for Random access, puts the values 1 through 10 in it, prints the contents, and closes the file again.
Sub Button_Click
' Put the numbers 1-10 into a file
Dim x As Integer, y As Integer
Open "C:\TEMP001" as #1
For x = 1 to 10
Put #1,x, x
Next x
msgtext = "The contents of the file is:" & Chr(10)
For x = 1 to 10
Get #1,x, y
msgtext = msgtext & y & Chr(10)
Next x
Close #1
Kill "C:\TEMP001"
End SubSee Also
Bookshelf Home | Contents | Index | Search | PDF | ![]() ![]() ![]() ![]() |
Siebel VB Language Reference Published: 18 June 2003 |