再判断条件是否为true,再决定是否继续循环 一、语法 init_expr do{ statement alter_expr }...
Do While Not EOF(1)'如果不是文件结尾就执行下面语句Input #1, inputFile, myNumber '读取文件数据写入变量inputFileMsgBox inputFile, myNumber '输出变量内容Loop Not EOF(1)表示不是文件结尾,同样数字1表示文件号。Do While...Loop循环是个判断语句,意思是当While后面的条件为真时执行loop之前的代码。如果...
Open "TESTFILE" For Input As #1 ' 打开输入文件。 Do While Not EOF(1) ' 循环至文件尾。 Input #1, MyString, MyNumber ' 将数据读入两个变量。 Debug.Print MyString, MyNumber ' 在立即窗口中显示数据。 Loop Close #1 ' 关闭文件。 9、Write # 语句 语法:Write #filenumber, [outputlist] 功...
Do While Not EOF(1) ' 循环至文件尾。 Input #1, MyString, MyNumber ' 将数据读入两个变量。 Debug.Print MyString, MyNumber ' 在立即窗口中显示数据。 Loop Close #1 ' 关闭文件。 9、Write # 语句 语法:Write #filenumber, [outputlist] 功能:将数据写入顺序文件。 说明:通常用 Input # 从文件读...
Do While Not EOF(1) '未到达结尾 Line Input #1, s1 '读入一行,放入s1变量中 Loop Close #1 4、LOC 函数 语法:LOC(filenumber) 功能:返回一个 Long,在已打开的文件中指定当前读/写位置。 Dim MyLocation, MyLine Open "TESTFILE" For Binary As #1 ' 打开刚创建的文件。
Do While Not EOF(1) Line Input #1, txt '从已打开的顺序文件中读出一行并将它分配给 String 变量 'Line Input # 语句一次只从文件中读出一个字符,直到遇到回车符 (Chr(13)) '或回车–换行符 (Chr(13) + Chr(10)) 为止。回车–换行符将被跳过,而不会被附加到字符串上 ...
Sub 将数据导入到excel中() Dim FilePath As String, LineData As String Dim arr() As String Dim i As Integer, j As Integer ' 设置文件路径 FilePath = "D:\Files\Desktop\test1.txt" ' 打开文件 Open FilePath For Input As #1 i = 1 ' 循环读取每一行 Do While Not EOF(1) ' 读取一行数...
Do While Not EOF(1)Input #1, name, class, num MsgBox name & ", " & class & ", " & num Loop Close #1 End Sub 看看代码截图:程序执行过程:上面的程序首先打开文件“E:\nz\work\文章\举例CSV.CSV”读取数据;并且建立一个Do…While循环,在整个文件里循环运行,直到文件的结尾;Input #1语句...
代码很简单,没几行,简单的了解一下。#VBA#Private Sub CommandButton1_Click()Dim Str As StringDim textFiles As StringClose #1'关闭已经打开的文件textFiles = ThisWorkbook.Path & "\txt\lineinput.txt"'设置文件以及路径Open textFiles For Input As #1'打开文件Do While Not EOF(1)'循环遍历文件行,...
Dim num As Integer Dim zhang As String num = 0 Open "E:\nz\work\文章\人员表单.txt " For Input As #1 Do While Not EOF(1)zhang = Input(1, #1)If zhang = "张" Then num = num + 1 End If Loop If num <> 0 Then MsgBox "表单中姓张的共: " & num & "人!"Else MsgBox "没...