如何在 Visual Basic 中使用 while 循环从 StreamReader 中读取数据? [英] How do I read from a StreamReader with a while loop in Visual Basic?
本文介绍了如何在 Visual Basic 中使用 while 循环从 StreamReader 中读取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑:
Dim line As String
Using readFile As New StreamReader(SalesUpdateFile)
While (line = readFile.ReadLine) IsNot Nothing
我是 Visual Basic 的新手.每次我运行这段代码时,它都会给我这个错误:
I am new to Visual Basic. And every time I run this code it gives me this error:
IS"需要一个具有引用类型的操作数
"IS" requires an operand that have a reference type
我该如何解决这个问题?
How can I fix this problem?
推荐答案
你不能在 VB 中使用赋值作为表达式.相反,你应该做类似这样的事情:
You can't use an assignment as an expression in VB. Instead you should do something similar to this:
line = readFile.ReadLine
While (line IsNot Nothing)
'process the line
line = readFile.ReadLine
End While
这篇关于如何在 Visual Basic 中使用 while 循环从 StreamReader 中读取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文