在VB里用浏览选择的TXT方法~~选择到一个TXT文件~~并将文件全部内容写到TEXT文本~
然后再问一下在TEXT文本改写了怎么保存回原来的文件~谢谢~~

解决方案 »

  1.   

    还有一个问题就是TXT的文件比较大~~~~~
    各位大侠帮帮忙~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~谢谢 ~~
      

  2.   

    Option ExplicitPrivate Sub loadfiletotext(ByVal s As String, t As TextBox)
        Dim l As Long
        l = FileLen(s)
        ReDim a(0 To l - 1) As Byte
        Open s For Binary As #1
        Get #1, , a
        Close #1
        t.Text = StrConv(a, vbUnicode)
    End SubPrivate Sub savetexttofile(t As TextBox, ByVal s As String)
        Open s For Output As #1
        Print #1, t.Text
        Close #1
    End Sub
    Private Sub Command1_Click()
        loadfiletotext "d:\temp001.txt", Text1
    End SubPrivate Sub Command2_Click()
        savetexttofile Text1, "d:\temp001.txt"
    End Sub
      

  3.   

    '添加 Command1  Command2  Text1  CommonDialog1
    'Text1的MultiLine 要设为True 文档太大的话可考虑改用 RichTextBoxDim fname$,FileOS As Boolean
    Private Sub Form_Load()
       Command1.Caption = "打 开"
       Command2.Caption = "保 存"
    End SubPrivate Sub Command1_Click()
       FileOS = True
       Call FOSprog
    End SubPrivate Sub Command2_Click()
       FileOS = False
       Call FOSprog
    End SubPrivate Sub FOSprog()
       On Error GoTo errhandler
       With CommonDialog1
          .CancelError = True
          .InitDir = App.Path '予设存档路径
          .Filter = "文档文件(*.txt)|*.txt"
          If FileOS Then
             .ShowOpen '打开文件
          Else
             .ShowSave '保存文件
          End If
       End With
       fname = CommonDialog1.FileName
       '从上面打开的记事本文件读入资料
       If FileOS Then
          Open fname For Input As #1
          Text1.Text = StrConv(InputB(LOF(1), 1), vbUnicode)
       Else
          Open fname For Output As #1
          Print #1, Text1.Text
       End If
       Close #1
    errhandler:
       If Err = 32755 Then Exit Sub '选择了取消
    End Sub