战旗tv放映室:VB编程(读随机文件)

来源:百度文库 编辑:中科新闻网 时间:2024/05/04 16:50:04
Dim y(32000) As Long
Dim x As Integer

Private Sub daorudate_Click()
'ReDim y(x)
With CommonDialog1
CommonDialog1.FileName = "*.dat"
CommonDialog1.Flags = 2048
CommonDialog1.Filter = "数据文件(*.dat)|*.dat|文本文件(*.txt)|*.txt"
CommonDialog1.FilterIndex = 1
CommonDialog1.DialogTitle = "导入数据"
CommonDialog1.Action = 1
If CommonDialog1.FileName = " " Then
MsgBox "请选择文件", 37
Else
Open CommonDialog1.FileName For Random As #11 Len = 8 '打开文件
'Do While EOF(11) = False '将文件的数据存入数组y(x)
'x = x + 1
'kj1% = x
'Loop 'Until EOF(11) = True
For x = 1 To 32000
Get #11, x, y(x)
Next x
End If
Close #11
End With
lixianfenxi.Enabled = True
End Sub
代码如上,
以运行出现提示
实时错误'458'
变量使用了一个VB不支持的自动化类型
在读文件的时候,无论时用Do循环,还是运用for循环,出现的提示一样。
put 是写文件语句,不是读文件语句

Get #11, x, y(x)
修改:
Put #11, x, y(x)