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
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
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.ReadAllprints the string returned byReadAllinto the file opened by numberiFileNumber(and because there is no semicolon after the statement, it also addsvbNewLinein the end.)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:vs.