VB随机文件记录长度错误

来源:百度知道 编辑:UC知道 时间:2024/05/10 08:44:36
我在一个程序中写
Type A_type

a(10) as int
b(10) as int

end type

dim A as A_type

1).Open XXX For Random As #1 len=Len(A)
它提示文件长度错误.

2).把它改成 : Open XXX For Random As #1 Len=256
可以了.
但用另一个程序打开(Open XXX For Random As #1 Len=256),读取数据的时候又是文件长度错误.

请问以上两个错误该怎么解决?

不知道你是怎么写的,但是我用你的写的,改了下是可以用的。
窗口:form1 模块:module1
模块里:
public type a_type
a(10) as integer
b(10) as integer
end type
public a as a_type
窗体里:
(我加了个text1用来输入想保存的文件内容,commond1用来确定保存文件内容)
Private Sub Command1_Click()
Dim record As Integer
Open "shuju.dat" For Random As #1 Len = Len(a)
record = LOF(1) / Len(a) + 1
Put #1, record, Text1.Text
Close #1
End Sub
保存下工程,运行下选择记事本打开那个文件夹下的shuju。dat就可以看见你在text1中写的文件内容了。

按上面回答,程序运行是没有问题,但是原问本来是用随机文件、按记录的方式存取文件,
如果改变了原目的,那能运行也没用啊。
原来要示是数组格式保存,结果改成了存字符串。这不合适