一行输入#语句,三行相同。每次都会覆盖变量吗?
在我从 vb6 迁移到 VB.net 的程序中,有 3 个 Line Input# 语句,它们都是一样的:
Line Input #9, dummy
Line Input #9, dummy
Line Input #9, dummy
这会每次都覆盖变量,还是会做一些愚蠢的事情,例如每次将输入附加到虚拟变量?
我的第二个问题,Input# 和 Line Input# 有什么区别?我一直在使用:
foo = bar.readline
for Input #.. 现在我担心我做错了,应该使用:
foo = bar.Read
或其他东西 非常感谢所有帮助
谢谢大家!
缺口
In a program I am migrating from vb6 to VB.net, there are three Line Input# statements, all the same:
Line Input #9, dummy
Line Input #9, dummy
Line Input #9, dummy
Will this just overwrite the variable each time, or do something stupid like append the input to dummy each time?
My second question, what's the difference between Input# and Line Input#? I had been using:
foo = bar.readline
for Input #.. and now I'm afraid that I've done it all wrong and should have used:
foo = bar.Read
or something
All help greatly appreciated
Thanks guys!
Nick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
令人惊讶的是,语言参考仍然可用。 输入#,行输入#。您是对的,它们不相同。
对于你的第一个问题,它会覆盖变量,所以这似乎是跳过两行并读取第三行的方法。
您可能最好使用 VB 运行时工具来读取 VB 6 生成的文件,而不是“.NET”风格的文件系统工作,因为我认为重现
的行为将非常困难使用
。使用Read
输入#FileSystem.Input
相反。The language reference is still, surprisingly, available. Input #, Line Input #. You're correct that they are not the same.
To your first question, it will overwrite the variable, so it just seems to be a way to skip 2 lines and read the third line.
You're probably better off using the VB Runtime facilities to read files that have been produced by VB 6, rather than the ".NET" style of filesystem work, since I think it would be quite difficult to reproduce the behaviour of
Input #
usingRead
. UseFileSystem.Input
instead.Line Input
语句读取输入文件中的所有文本,直到下一个CR
或CR-LF
序列,并将其放入变量 <代码>虚拟。因此,正如您猜测的那样,这些语句每次都会覆盖变量dummy
。Input
读取输入,直到下一个CR
、CR-LF
序列或分隔逗号,并将读取的数据保存在dummy
中>。我倾向于认为你是对的,你真的应该使用
bar.Read
作为Input #
和bar.ReadLine
作为>输入行
。请参阅输入#和行输入#了解更多信息。
The
Line Input
statement reads all the text in the input file up until the nextCR
orCR-LF
sequence and puts it in the variabledummy
. So these statements will, as you surmise, overwrite the variabledummy
each time.Input
reads input until the nextCR
,CR-LF
sequence or delimiting comma, and saves the data read indummy
.I'm inclined to the view that you are right, you should really use
bar.Read
forInput #
andbar.ReadLine
forInput Line
.See Input # and Line Input # for more.
行输入#命令不会不要做任何特殊的事情,比如附加到变量上。该值只是分配给变量,因此如果您有这样的三行,它将覆盖前两个值。
Read #
命令需要特殊的数据格式,因此ReadLine
无法替代。 Write # 命令的参考包含有关Read #
命令期望的数据外观的详细信息。The Line Input # command doesn't do anything special like appending to the variable. The value is simply assigned to the varaible, so if you have three lines like that it will overwrite the first two values.
The
Read #
command expects a special format for the data, soReadLine
won't work as a replacement. The reference for the Write # command has details for how the data looks that theRead #
command expects.