computer 版 (精华区)
发信人: windoe (为中国电信做贡献), 信区: program
标 题: VB:如何把变量的数据写入文件,再从文件里读出来?
发信站: 听涛站 (Fri Mar 10 19:09:01 2000), 转信
文件的操作有打开文件(Open)、写入文件(Write)、读取文
件(Input),关闭文件(Close)。
’写入文件操作
Function SaveData(fname$) As Boolean
On Error Resume Next ’设置错误处理
Dim int1 As Integer
Dim str1 As String
Dim X As Integer
int1=20 ’变量赋初值
str1=“这是字符串”
X = FreeFile ’取得一个空闲文件句柄
Open fname$ For Output As X ’试图打开该文件
If Err <> 0 Then ’如果打开不成功
SaveData=False
Exit Function
End If
Write X, int1,str1
Close X
SaveData=True
SaveData=True
End Function
’读取文件操作
Function ReadData(fname$) As Boolean
On Error Resume Next ’设置错误处理
Dim int1 As Integer
Dim str1 As String
Dim X as Integer
X = FreeFile ’取得一个空闲文件句柄
Open fname$ For Input As X ’试图打开该文件
If Err <> 0 Then ’如果打开不成功
ReadData=False
Exit Function
End If
Input X, int1,str1
Close X
ReadData=True
’输入执行结果
Debug.Print int1,str1
End Function
--By Kammi's SuperPost General Version
--
夜中不能寐,起坐弹鸣琴。
薄帷鉴明月,清风吹我襟。
孤鸿号外野,翔鸟鸣北林。
徘徊将何见,忧思独伤心。
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:1.562毫秒