请教高手怎么用vb编写读取文本下一行

如果读取到一行是空的,则直接把下一行的内容显示出来。这个怎么弄啊,大家帮帮忙

dim tem as string,fildata as string
open "文件" for input as #1
do until eof(1)
line input #1,tem '读取的这一行的内容存入变量tem
if tem="" then '如果这行的内容是空的就显示下一行内容
line input #1,filedata '将空行的下一行内容存到变量filedata
print "读取的内容是:" & filedata
end if
loop
close #1
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-01-16
先读一行,放入一个变量a,
If a="" then
再读下一行
End If

参考一下,上面的汉字总分怎么改成程序,我想你应该知道。
第2个回答  2009-01-16
1.直接读取文本

Private Sub Command1_Click()
Dim i As Integer
Dim a
Dim b

Open "c:\1.txt" For Binary As #1
a = StrConv(InputB(LOF(1), 1), vbUnicode)
Close #1

b = Split(a, vbCrLf)

For i = 0 To UBound(b)
If b(i) = "" Then
Print b(i + 1)
End If
Next i
End Sub

2.使用文件系统读取文本

Private Sub Command1_Click()
Dim FSO As New FileSystemObject
Dim TS As TextStream

Set TS = FSO.OpenTextFile("C:1.txt", ForReading, True)
Do Until TS.ReadLine = ""
TS.ReadLine
Loop
Print TS.ReadLine
TS.Close
Set FSO = Nothing
End Sub

需要在工程中引用Microsoft scripting Runtime
第3个回答  2019-05-06
文件已发送到邮箱,请及时查收!
相似回答
大家正在搜