从vb6代码使用vb.net保存文件以获得优秀

时间:2013-09-27 13:26:39

标签: vb.net vb6

我有一个需要在vb.net上运行的vb6代码

 Dim strFileName As String
    Dim strText As String
    Dim strFilter As String
    Dim strBuffer As String
    Dim FileHandle%

    strFilter = "Comma Seperated File (*.csv)|*.csv"
    CDMAIN.Filter = strFilter
    CDMAIN.ShowSave
    If CDMAIN.FileName <> "" Then
        strFileName = CDMAIN.FileName
        strText = Text1.Text
        FileHandle% = FreeFile

'''''''''''''''''''''''''''''''''''''''''''''''''''''''

        Open strFileName For Output As #FileHandle%
        MousePointer = vbHourglass
        Print #FileHandle%, strText
        MousePointer = vbDefault
        Close #FileHandle%
    End If

该功能将数据保存到excel文件

1 个答案:

答案 0 :(得分:0)

    Open strFileName For Output As #FileHandle%
    MousePointer = vbHourglass
    Print #FileHandle%, strText
    MousePointer = vbDefault
    Close #FileHandle%

转换为VB.NET代码:

    Me.Cursor = Cursors.WaitCursor
    Using fs As New StreamWriter(strFileName, False)
        fs.WriteLine(strText)
    End Using
    Me.Cursor = Cursors.Default