2010/1/4 Bernard Marcelly <[email protected]>:
> Message de Johnny Rosenberg  date 2010-01-01 13:58 :
>>
>> The first thing I did was to look in AndrewMacro.odt, the famous macro
>> document by Andrew Pitonyak. I found this example, and I actually also
>> found the same example in the OpenOffice.org BASIC help section, that
>> seems to be broken though (I added line numbers to it, so I can easier
>> refer to it later):
>> 00. '?? This is broken!
>> 01. Sub ExampleRandomAccess
>> 02.   Dim iNumber As Integer, aFile As String
>> 03.   Dim sText As Variant REM Must be a variant
>> 04.   aFile = "c:\data1.txt"
>> 05.   iNumber = Freefile
>> 06.   Open aFile For Random As #iNumber Len=5
>> 07.   Seek #iNumber,1 REM Position at beginning
>> 08.   Put #iNumber,, "1234567890" REM Fill line with text
>> 09.   Put #iNumber,, "ABCDEFGHIJ"
>> 10.   Put #iNumber,, "abcdefghij"
>> 11.   REM This is how the file looks now!
>> 12.   REM 08 00 0A 00 31 32 33 34  35 36 37 38 39 30 08 00
>> ....1234567890..
>> 13.   REM 0A 00 41 42 43 44 45 46  47 48 49 4A 08 00 0A 00
>> ..ABCDEFGHIJ....
>> 14.   REM 61 62 63 64 65 66 67 68  69 6A 00 00 00 00 00 00   abcdefghij
>> 15.   REM
>
> Hi Johnny,
> A Random access file has no real meaning for text.
>
> It would be much simpler to write an ordinary text file with successive
> lines
> using instruction Print, and later read the file line by line using
> instruction
> Line Input. For random access, put the lines in an array of String.
>
> Regards
>  Bernard

Thank you, Bernard. When I couldn't get the example from the
OpenOffice.org help to work, I actually solved my problem by reading
the file to an array of strings, manipulate the array and create a new
file from that array.

Anyway, since this example can be found in the help section of
OpenOffice.org, shouldn't that example be replaced by an example that
actually works? And if the example was somewhat realistic, it would be
even better…

Regards

Johnny Rosenberg

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to