哈希对VB中的变量有什么作用? [英] What does a hash do to a variable in VB?

查看:62
本文介绍了哈希对VB中的变量有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将VB6程序重构为C#,并坚持理解以下几行:

I have to refactor a VB6 program to C# and am stuck at understanding the following lines:

Set myFileSystemObject = New FileSystemObject
Set myTextStream = myFileSystemObject.OpenTextFile("myTextFile.txt")
Open sPrinterPort For Output As iFileNumber
Print #iFileNumber, myTextStream.ReadAll
Close #iFileNumber

我确实知道一般情况,但是由于我不习惯VB语法,所以我想确切地知道什么

I do know what's generally happening, but as I'm not used to the VB syntax, I'd like to know exactly what

Print #iFileNumber, myTextStream.ReadAll

确实.更具体地说,是iFileNumber前面的#的作用.为什么在那儿?变量本身不足以在流上打印吗?

does. And more specifically, what the # in front of iFileNumber does. Why is it there? Wouldn't the variable itself suffice to print on the stream?

这仅仅是为了准确了解代码中正在发生的事情.

This is merely for understanding exactly what's happening in the code.

推荐答案

Print #iFileNumber, myTextStream.ReadAllReadAll返回的字符串打印到以数字iFileNumber打开的文件中(并且由于语句后没有分号,所以它也最后添加vbNewLine.

Print #iFileNumber, myTextStream.ReadAll prints the string returned by ReadAll into the file opened by number iFileNumber (and because there is no semicolon after the statement, it also adds vbNewLine in the end.)

#(用于数字")自古以来就存在. VB6只支持它.它没有执行明智的选择.它曾经用于辅助可读性并使该语言更自然.大声说出来:

The # (for "number") is there since the old times. VB6 just supports it. It does nothing execution wise. It used to assist readability and make the language more natural-like. Speak out loud:

Open "1.txt" For Input As 1

vs.

Open "1.txt" For Input As #1

这篇关于哈希对VB中的变量有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆