Opening a text file for random access

I am trying to move from vb6 to XOJO but as of yet i haven’t been able to figure out how to open a file for random access. What is the xojo equivalent of:

open “c:\med\test.txt” for random as #1 len= 256

There isn’t one… but it can be duplicated by creating an array… or maybe a memoryblock

You would probably want to use Binary Streams for this.

I haven’t done this myself, but you can read/write strings from your files using a binary stream, and then Set/Get a the data of the structure using MyStructure.StringValue. See Structure .

Using BinaryStreams together with the StringValue property of structures, should give you the same effect as random access files in VB6.

My office uses hundreds of floppys with RA files for patient information. I need a simple way of reading these files. IT seems like this isnt possible with xojo? I know floppy and RA files are both more than dated but the boss wants to stasy this way. would it be easier in these cases where i need to use RA files to stay in vb6?

Have a look at binary streams. Takes a little bit getting used to, but very powerful for such file operations.

Read it in once - convert it to a sqlite database (which is vastly more flexible) and be done with it

Or you can use a binary stream with a fixed sized structure & a binary stream

If the files are plain ASCII/ANSI etc. where 1 byte is 1 character then you should be able to cook up something using the binary stream. If the files could be something ‘modern’ like Unicode UTF8 (variable width encoding) then it is a bit more complicated because 1 character could be 1 - 4 bytes and even more complicated because in some character sets the characters can be ‘composite’ for example can be represented as a single character or a combination of e and an a special ‘combining’ acute accent. Unicode files make most sense when read from start to finish as you can imagine and I expect this is why the Xojo stream reader reads forwards. Most operating systems deal with the encoding and decoding at an OS level.

if you files are in some record format you could convert your files once as Norman suggests. If you really need some kind of ability to jump around randomly then you could consider reading them into an array of string characters or lines (assuming that they are not huge).