【问题标题】:Equivalent of "Open fileName For Output As #1" VB6 to .NET“Open fileName For Output As #1”VB6 到 .NET 的等效项
【发布时间】:2012-03-28 11:20:31
【问题描述】:

另一个迁移问题,

我还有另一块 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 中实现相同的功能?感谢大家的帮助。

洛根

【问题讨论】:

  • 只是 StreamWriter 及其 WriteLine() 方法。

标签: vb.net printing vb6 io vb6-migration


【解决方案1】:
 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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多