I don't understand.
Your code properly works for stringtype:
Code: Select all
#include "file.bi"
type stringtype 'can save and reload this type efficiently from disk
as string * 18 value
as long index
as long occurrency
declare operator cast() as string
end type
operator stringtype.cast() as string 'print out the stringtype results
print "'";value;"'"
print index
print occurrency
return ""
end operator
sub loadfile(file as string,b() as stringtype)
If FileExists(file)=0 Then Print file;" not found":Sleep:end
var f=freefile
Open file For Binary Access Read As #f
If Lof(f) > 0 Then
Get #f, , b()
End If
Close #f
end sub
Sub savefile(filename As String,p() As stringtype)
Dim As Integer n
n=Freefile
If Open (filename For Binary Access Write As #n)=0 Then
Put #n,,p()
Close
Else
Print "Unable to load " + filename
End If
End Sub
dim as string z="AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
#define range(f,l) Int(Rnd*((l+1)-(f))+(f))
dim as stringtype st(1 to 10)
'create some instances of stringtype
for n as long=1 to ubound(st)
with st(n)
.value=mid(z,range(1,(52-18)),18)
.index=n
.occurrency=range(5,15)
end with
next n
print "Save this data to file:"
print
for n as long=lbound(st) to ubound(st) 'show them
print st(n)
next
print "____________________________"
print
savefile("text.txt",st())
erase st
'reload from drive
var lngth=filelen("text.txt")\sizeof(stringtype) 'get incoming array dimension
dim as stringtype y(1 to lngth)
loadfile("text.txt",y())
print "Returned data:"
print
for n as long=lbound(st) to ubound(st) 'show them
print y(n)
next
sleep
Code: Select all
Save this data to file:
'fGgHhIiJjKkLlMmNnO'
1
8
'JjKkLlMmNnOoPpQqRr'
2
13
'kLlMmNnOoPpQqRrSsT'
3
12
'FfGgHhIiJjKkLlMmNn'
4
15
'QqRrSsTtUuVvWwXxYy'
5
15
'JjKkLlMmNnOoPpQqRr'
6
12
'BbCcDdEeFfGgHhIiJj'
7
12
'AaBbCcDdEeFfGgHhIi'
8
10
'aBbCcDdEeFfGgHhIiJ'
9
10
'OoPpQqRrSsTtUuVvWw'
10
13
____________________________
Returned data:
'fGgHhIiJjKkLlMmNnO'
1
8
'JjKkLlMmNnOoPpQqRr'
2
13
'kLlMmNnOoPpQqRrSsT'
3
12
'FfGgHhIiJjKkLlMmNn'
4
15
'QqRrSsTtUuVvWwXxYy'
5
15
'JjKkLlMmNnOoPpQqRr'
6
12
'BbCcDdEeFfGgHhIiJj'
7
12
'AaBbCcDdEeFfGgHhIi'
8
10
'aBbCcDdEeFfGgHhIiJ'
9
10
'OoPpQqRrSsTtUuVvWw'
10
13