vb.net - 相当于 "Open fileName For Output As #1"VB6 到 .NET

标签 vb.net printing vb6 io vb6-migration

另一个迁移问题,

我还有另一段 VB6 代码,似乎需要一些针对 .NET 的解决方法。对于缩短版本,这就是它所做的一切:

Open sFileName For Output As #1
Print #1,
Print #1, "Facility:" & vbTab & Replace(Frame1.Caption, ",", " ")
Print #1, 
Print #1, "Address:" & vbTab & Replace(Me.lblAddr1.Caption, ",", " ")
Print #1, "City/State:" & vbTab & Replace(Me.lblAddr2.Caption, ",", " ")

等等等等。您可以看到它不断重复以创建新行。问题是,我如何在 .NET 中实现同样的事情?感谢所有帮助的家伙。

洛根

最佳答案

 Imports System
 Imports System.IO
 Imports System.Text
 Imports System.Collections.Generic

 Class Program

    Public Shared Sub Main(ByVal args As String())

    Dim mydocpath As String = _
    Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
    Dim sb As New StringBuilder()

    For Each txtName As String _
        In Directory.EnumerateFiles(mydocpath, "*.txt")
        Using sr As New StreamReader(txtName)
            sb.AppendLine(txtName.ToString())
            sb.AppendLine("= = = = = =")
            sb.Append(sr.ReadToEnd())
            sb.AppendLine()
            sb.AppendLine()

        End Using
    Next

    Using outfile As New StreamWriter(mydocpath & "\AllTxtFiles.txt", Encoding.Default)
        outfile.Write(sb.ToString())
    End Using
    End Sub
 End Class

http://msdn.microsoft.com/en-us/library/6ka1wd3w.aspx#Y0

关于vb.net - 相当于 "Open fileName For Output As #1"VB6 到 .NET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9660632/

相关文章:

html - 不同的浏览器以不同的方式显示 HTML

vb.net - 使用 DLL 中的类创建 VB6 应用程序,然后在构建后换出该 DLL?

vb.net - 通过变量名访问 VB.Net 结构元素

python - 为什么我的函数不打印

security - VB6 中的 CheckTokenMembership - 在 Windows 7 和 Windows 2008 上的 FreeSID 上崩溃

vba - 为什么 IDL 默认值看起来是四舍五入的?

sql-server - 提供的时间值的小数部分溢出异常 SQL Server 2017

Swift Print 函数格式化

c++ - 如何获取脚本以在 C++ 中插入整个用户输入

wpf - 我如何检查是否使用 VB6 在 PC 上安装了 "Microsoft Edge WebView2 Runtime"或 "Microsoft Edge Insider Channels"金丝雀