vb 修改文件

来源:百度知道 编辑:UC知道 时间:2024/06/21 06:01:45
这个是我做的,我有2个问题,一是我本来已经关了file了,但是电脑有时候提示说file以打开,所以第2次打开file就不行。第2个问题是我本来是想把array里的数字和strNum加一起得一个新的数字,但是我却得到两个数字并列在一起出现。比如 1+1,我想要2,但是写到文件是11
Dim intFile1 As Integer
Dim strAns(1 To 1000) As String
Dim intCount As Integer
intFile1 = FreeFile
Open "C:\Downloads\Save.txt" For Input As intFile1
Do While (Not EOF(intFile1))
intCount = intCount + 1
Line Input #intFile1, strAns(intCount)
Loop
Close #intFile1
strAns(1) = strAns(1) + strNum
intFile1 = FreeFile
Open "C:\\Downloads\Save.txt" For Output As intFile1
Print #intFile1, strAns(1)
Close #intFile1
frmFinish.Show
Un

给你改了一下,你试试看
Dim strAns(1 To 1000) As String
Dim intCount As Integer
Open "C:\Downloads\Save.txt" For Input As #1
Do While (Not EOF(intFile1))
intCount = intCount + 1
Line Input #intFile1, strAns(intCount)
Loop
Close #1
strAns(1) = Val(strAns(1)) + strNum
intFile1 = FreeFile
Open "C:\Downloads\Save.txt" For Output As #1
Print #intFile1, strAns(1)
Close #1
frmFinish.Show
Unload Me