Code: Select all
#include "file.bi" ' for FileExists()
Function Recall(fname As String, locArray() As String) As Integer
Dim As Integer ct=0, cursize=100 ' locArray is a local representation of a dynamic array
If Open(fname For Input As #1) = 0 Then
Do While Not Eof(1)
if ct=0 or ct>cursize then
cursize+=cursize shr 1
ReDim Preserve locArray(cursize)
endif
Line Input #1, locArray(ct)
ct+=1
Loop
Close #1
ReDim Preserve locArray(ct)
Else
Print "Error opening file"
End If
Return ct
End Function
Dim MyArray() As string
if FileExists("test.tmp")=0 then
Open "test.tmp" for output as #1
For i As Integer=0 To 9
if i<>5 then
Print #1, "This is string #";i
else
Print #1, ""
endif
Next
Close #1
Print "Testfile created"
endif
if Recall("test.tmp", MyArray()) then
Print "records loaded:";ubound(MyArray)
For i As Integer=0 To ubound(MyArray)-1 ' print the first and last Cells
if StrPtr(MyArray(i))=0 then
print "### nullpointer in line";i;" ###"
endif
Print i, MyArray(i)
Next
Print "OK"
endif
Sleep