vb 如何读写指定路径的txt文件等(具体如下……)

来源:百度知道 编辑:UC知道 时间:2024/06/03 04:17:59
控件如下:
label.caption="一月份"
textBox1.text=10
textBox2.text=20
textBox3.text=30
问题一:我想把以上3个数据以txt格式保存到“c:\”下,格式如下:
一月份
10
20
30
问题二:我想在每次“打开”程序时自动读入以上数据,同样的格式。
还有加分,希望答案能详细点,谢谢啦!

写:
open "c:\a.txt" for output as #1
print #1,label.caption
print #1,textBox1.text
print #1,textBox2.text
print #1,textBox3.text
close #1

读:
open "c:\a.txt" for input as #1
line input #1,label.caption
line input #1,textBox1.text
line input #1,textBox2.text
line input #1,textBox3.text
close #1

Private Sub Form_Load()
pa = "c:\a.txt"
If Dir(pa) <> "" Then
Open pa For Input As #1
Line Input #1, a1
Line Input #1, a2
Line Input #1, a3
Line Input #1, a4
Close #1
Label1.Caption = a1
Text1 = a2
Text2 = a3
Text3 = a4

End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
Open "c:\a.txt" For Output As #1
Print #1, Label1.Caption
Print