Random
 
Specifies file or device to be opened for binary mode

Syntax

Open filename for Random [Access access_type] [Lock lock_type] as [#]filenum [Len = record_length]

Parameters

filename
file name to open
access_type
indicates whether the file may be read from, written to or both
lock_type
locking to be used while the file is open
filenum
unused file number to associate with the open file
record_length
the size of the record used for the file

Description

Opens a file or device for reading and/or writing binary data in the given file filenum, with records of size record_length.
If the file does not exist, a new file will be created, otherwise any data existing in the file is preserved by Open. The file pointer is initialized by Open at the start of the file, at record number 1. File operations move the file position in steps of record_length bytes.
This file mode uses an user-defined Type buffer variable to read/write full records in a file. The buffer variable uses to include several fields.
The data is saved in binary mode, in the same internal format FreeBASIC uses, by means of Get # and Put #.

filename must be string expression resulting in a legal file name in the target OS, without wildcards. The file will be sought for in the present directory, unless a path is given.
Access_type - By default Random mode allows to both read and write the file, unless an Access type is specified, it must be one of:
    • Read - the file is opened for input only
    • Write - the file is opened for output only
    • Read Write - the file is opened for input and output (the default)

Lock_type indicates the way the file is locked for other processes (users or threads), it is one of:
    • Shared - The file can be freely accessed by other processes
    • Lock Read - The file can't be opened simultaneously for reading
    • Lock Write - The file can't be opened simultaneously for writing
    • Lock Read Write - The file cannot be opened simultaneously by other processes.
If no lock type is stated, the file will be Shared for other threads of the program and Lock Read Write for other programs.
Lock and Unlock can be used to restrict temporally access to parts of a file.

filenum is a valid FreeBASIC file number (in the range 1..255) not being used for any other file presently open. This number identifies the file for the rest of file operations. A free file number can be found using the FreeFile function.

record_length is the amount of bytes the file pointer will move for each individual Get and Put, it must match the size of the buffer variable used when Getting and Putting data. If omitted, it defaults to 128.

Example

Type UDT
    slen As Byte
    sdata As String * 10
End Type

Dim i As Integer
Dim s As String
Dim u As UDT

Dim ff As UByte
Dim fpos As Integer

ff = FreeFile
fpos = 10

Open "testfile" For Random As #ff Len=SizeOf(UDT)
For i = 1 To 9
    Read s
    u = Type( Len(s), s )
    Put #ff, i, u
Next

Do
    Input "Record number: ", i
    If i < 1 Or i > 9 Then Exit Do
    Get #1, i, u
    Print i & ": " & Left( u.sdata, u.slen )
    Print
Loop

Close #ff
End 0

Data ".,-?!'@:", "abc",      "def"
Data "ghi",      "jkl",      "mno"
Data "pqrs",     "tuv",      "wxyz"


Differences from QB

  • In QB, String-contained runtime user defined types (UDT) are not implemented in FreeBASIC.
  • The keyword Field can only be used with Type to specify the packing of the UDT.

See also

Сайт ПДСНПСР. Если ты патриот России - жми сюда!


Знаете ли Вы, что, когда некоторые исследователи, пытающиеся примирить релятивизм и эфирную физику, говорят, например, о том, что космос состоит на 70% из "физического вакуума", а на 30% - из вещества и поля, то они впадают в фундаментальное логическое противоречие. Это противоречие заключается в следующем.

Вещество и поле не есть что-то отдельное от эфира, также как и человеческое тело не есть что-то отдельное от атомов и молекул его составляющих. Оно и есть эти атомы и молекулы, собранные в определенном порядке. Также и вещество не есть что-то отдельное от элементарных частиц, а оно состоит из них как базовой материи. Также и элементарные частицы состоят из частиц эфира как базовой материи нижнего уровня. Таким образом, всё, что есть во вселенной - это есть эфир. Эфира 100%. Из него состоят элементарные частицы, а из них всё остальное. Подробнее читайте в FAQ по эфирной физике.

НОВОСТИ ФОРУМАФорум Рыцари теории эфира
Рыцари теории эфира
 10.11.2021 - 12:37: ПЕРСОНАЛИИ - Personalias -> WHO IS WHO - КТО ЕСТЬ КТО - Карим_Хайдаров.
10.11.2021 - 12:36: СОВЕСТЬ - Conscience -> РАСЧЕЛОВЕЧИВАНИЕ ЧЕЛОВЕКА. КОМУ ЭТО НАДО? - Карим_Хайдаров.
10.11.2021 - 12:36: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от д.м.н. Александра Алексеевича Редько - Карим_Хайдаров.
10.11.2021 - 12:35: ЭКОЛОГИЯ - Ecology -> Биологическая безопасность населения - Карим_Хайдаров.
10.11.2021 - 12:34: ВОЙНА, ПОЛИТИКА И НАУКА - War, Politics and Science -> Проблема государственного терроризма - Карим_Хайдаров.
10.11.2021 - 12:34: ВОЙНА, ПОЛИТИКА И НАУКА - War, Politics and Science -> ПРАВОСУДИЯ.НЕТ - Карим_Хайдаров.
10.11.2021 - 12:34: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от Вадима Глогера, США - Карим_Хайдаров.
10.11.2021 - 09:18: НОВЫЕ ТЕХНОЛОГИИ - New Technologies -> Волновая генетика Петра Гаряева, 5G-контроль и управление - Карим_Хайдаров.
10.11.2021 - 09:18: ЭКОЛОГИЯ - Ecology -> ЭКОЛОГИЯ ДЛЯ ВСЕХ - Карим_Хайдаров.
10.11.2021 - 09:16: ЭКОЛОГИЯ - Ecology -> ПРОБЛЕМЫ МЕДИЦИНЫ - Карим_Хайдаров.
10.11.2021 - 09:15: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от Екатерины Коваленко - Карим_Хайдаров.
10.11.2021 - 09:13: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от Вильгельма Варкентина - Карим_Хайдаров.
Bourabai Research Institution home page

Боровское исследовательское учреждение - Bourabai Research Bourabai Research Institution