VB读入 保存数据代码问题

来源:百度知道 编辑:UC知道 时间:2024/05/15 16:17:55
一个文本框,两个命令按钮”读入数据””保存数据”.写代码
点”读入数据”按钮,则读入"in.txt"中的100个整数,放入一个数组中(数组下界为1)并在text1中显示出来.点”保存按钮”在把数组中的前50个数据在文本框中显示出来,并保存到”result.txt”中
麻烦各位给写个代码
小弟先谢过了

Option Explicit
Option Base 1

Dim A
Dim b(100)
Private Sub Command1_Click()
Dim Str1 As String
Open App.Path & "\in.txt" For Input As #1
Line Input #1, Str1
Close #1
A = Split(Str1, " ")
End Sub

Private Sub Command2_Click()
Dim i
For i = 1 To 50
Text1.Text = Text1.Text & A(i) & " "
Next
Open App.Path & "\Result.txt" For Output As #1
Print #1, Text1.Text
Close #1
End Sub

Private Sub Form_Load()
Dim i
Open App.Path & "\in.txt" For Output As #1
For i = 0 To 99
Print #1, i & " ";
Next
Close #1
Command1.Caption = "读入数据"
Command2.Caption = "保存数据"
Text1.Text = ""
End Sub

Open "C:\abc.txt" For Binary As #1
Text1.Text = Input(LOF(1), #1)
Close #1

三行语句即可把文件所有内容读入Text1,而且没有用到任何变量