vb open 怎么用? do loop中的语句有什么用?

来源:百度知道 编辑:UC知道 时间:2024/07/02 08:28:47
Private Sub Form_Load()
Dim str1 As String
Text1.Text = ""
Open App.Path & "\in5.txt" For Input As #1
Do While Not EOF(1)
Input #1, str1
Text1.Text = Text1.Text + str1
Loop
Close #1
End Sub
Private Sub Cmd1_Click()
Open App.Path & "\out5.txt" For Output As #1
Print #1, Text1.Text
Close #1
End Sub

Open App.Path & "\in5.txt" For Input As #1只读方式打开
do while not eof(1)
循环代码
loop
while就是当…为真时
eof(1)就是判断你打开的#1文件是否读完。
这个循环意思就是当#1文件没有读完时,执行循环代码。
把文本文档的数据都保存到text1.text中
Open App.Path & "\out5.txt" For Output As #1用output打开文件,如果文件不存在,会自动创建一个文件并打开,如果文件存在,就删除所有数据然后打开。
print #1 ,text1.text
把text1.text再写到out5.txt中。

它是一个循环
do while 条件

循环体
loop
open用来打开in5.txt这个文件,并把内容放到text1中

Open语句用来打开一个文件,格式为:
Open 文件名 For 模式 As[#]文件号 [Len=记录长度]
do loop为循环结构

open 是打开文件
do 是循环
我这有很多实例你要吗?
qq 584556443

Private Sub Form_Load()
Dim str1 As String
Text1.Text = ""
Open App.Path & "\in5.txt" For Input As #1
Do While Not EOF(1) ,当没读到文件结尾 EOF End Of File( 编号)
Input #1, str1
Text1.Text = Text1.Text + str1
Loop
Close #1
End Sub
Private Sub Cmd1_Click